LibGDX Box2D Tiled Tutorial - Block Bunny - Part 2 - Box2D 101 : Bodies, Fixtures, Units

  Рет қаралды 61,771

ForeignGuyMike

ForeignGuyMike

Күн бұрын

Пікірлер: 184
@soleypas
@soleypas 8 жыл бұрын
BOX2D is explained very well! Thank you so much! I had tough time understanding PPM and how to apply it!
@FlorianEagox
@FlorianEagox 8 жыл бұрын
Watching Brent Aurelia's Tuts and then watching these really clears everything up! Great videos.
@spilot14
@spilot14 8 жыл бұрын
After lurking your channel for a couple of days and actually created a functional game with your help, I'm so eternally grateful for your concise descriptions of methods and concepts. 10/10. The speed that you go at is perfect. Since when have you been toying with gdx? It feels like its your second nature when it comes manipulating it.
@haxpor
@haxpor 7 жыл бұрын
This is pretty much sums up the basic most people should know first in very short time, and very concise and very understandable! Thanks!
@hwudiwkbwhsysiwkmwbsoslkwaauyy
@hwudiwkbwhsysiwkmwbsoslkwaauyy 10 жыл бұрын
Literally can't find one wrong thing about your tutorials, they're great! Thanks alot!
@soleypas
@soleypas 8 жыл бұрын
Also separating Box2D camera from game camera was a very good idea. I was running into precision issue as I have already have some zoom and adding PPM was making extra spaces between tiles!
@Oakiee
@Oakiee 9 жыл бұрын
This tutorial is great so far! It is still relevant even though you made it over a year ago.
@АлександрБабанский
@АлександрБабанский 9 жыл бұрын
I searched this information 1 day. Big thanks!
@eToxSuuri
@eToxSuuri 10 жыл бұрын
Awesome tutorial, buddy! Very easy to understand and are very entertaining to watch. Thank you for your efforts :)
@branisgreat
@branisgreat 10 жыл бұрын
Your tutorials are great! Keep it up
@Quaid2k
@Quaid2k 10 жыл бұрын
Hi Mike, I'm using the latest libGdx. I have used GL20, GL10 isn't available. On each bounce the box get slightly higher and it's set to Earth's gravity. I will type it all out again to be sure. I was wondered if you'd encounter any issues with the latest Gdx library. Also, it's really choppy when running on my android device, screen flashes a little too?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
The problem was with the render() loop I used. I decided to remove the accumulator in Game.java and just let it run update() and render() on each loop. ie: public void render() { gsm.update(Gdx.graphics.getDeltaTime()); gsm.render(); } But that means you need to fix your Box2D world timestep. world.step(1 / 60f, 1, 1);
@Quaid2k
@Quaid2k 10 жыл бұрын
ForeignGuyMike Thanks for your time Mike, that's fixed it :)
@vinceemigh9523
@vinceemigh9523 9 жыл бұрын
In the render method of Play, you changed cam.combined to the new b2dCam.combine. Is there still a use for the previous camera? Or can it be deleted?
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
Vince Emigh cam is the regular cam. b2dCam is only for drawing Box2D debug outlines.
@danielmenesespt
@danielmenesespt 10 жыл бұрын
Hi Mike, why do really need to do a while loop on Game Class in render method? Seems to me that a while loop it's already implemented in this method by the libgdx framework! So shouldn't you change it to an if statement? Just trying and understand the need if you can explain it to me! thanks
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
I had this weird notion to try to sync up the render loop to the Box2D world step. The while loop I used made sure that the game loop only ran in exact intervals of 1/60f, which is what I used to run the Box2D step. Anyway, it doesn't really matter. You should get rid of the while loop and just let it run one update() and render() per loop. But that means you also need to fix the Box2D world step to 1/60f. world.step(1/60f, 1, 1);
@Htrom1
@Htrom1 10 жыл бұрын
Question. Do you notice the small green pixel located between the Dynamic Body box and the Static box in the lower left hand corner of the Dynamic box? Do you know why that's there?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
The dots are to show contact between two fixtures. In this case, it's the box and the floor.
@coversbvk
@coversbvk 10 жыл бұрын
I get an error here: BodyDef bdef = new BodyDef(); bdef.position.set(160,120); Syntax error on token(s), misplaced construct(s) Also when i type bdef. en then press ctrl+space it says 'no default proposals'. I imported everything and I used the gradle setup. Why does it not work?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Game programming is not for beginners. If you don't know how the code is structured in class files and methods, you should not be here.
@betterw.petter3034
@betterw.petter3034 10 жыл бұрын
ForeignGuyMike Could you elaborate? I am having the same issue, and from the docs the position is a Vector2D and that class has no method "set". Hence I am getting an error saying "Cannot resolve symbol set".. Ops! My bad, I accidently started writing outside of the constructor
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Better w. Petter And that's why I told him about not starting with game programming. Since he doesn't know to put code inside methods.
@coversbvk
@coversbvk 10 жыл бұрын
Yeah sorry, I didn't see that before asking. I know how to program, just wasn't paying attention..
@dmitryantipov3726
@dmitryantipov3726 10 жыл бұрын
Thank you! Excellent tutorial!
@jaycalli40
@jaycalli40 10 жыл бұрын
ForeignGuyMike Excuse me, for some reason I can't get the world to display the Body stuff and the whole test thing to see if it can draw the "play state" text doesn't work either. Any thoughts? Greatly appreciated.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
"body stuff" "test thing" You have to be more specific than that. The test thing is from the first video. This is the second video. In order to make things clear, if the problem isn't in this video, tell me which video it's in. The test string isn't drawing? Is the draw() method even running? Find out. If it is running, then that means the test string is being drawn, but you just can't see it. Most likely it's because you're drawing with the wrong camera. *Any time you draw anything, you must specify the camera to use. Drawing is useless without a camera.* What camera are you using to draw the string? Is it set to the correct dimensions? Are you setting the SpriteBatch to use that camera? By the way, if the String isn't even being drawn, you shouldn't be on this second video. Solve the String draw problem first. Don't even look at the Box2D.
@jaycalli40
@jaycalli40 10 жыл бұрын
ForeignGuyMike Nvm, I found the issue. I forgot to add the code for update and render in GameStateManager. Sorry for being very unspecific, I am very new to libgdx and have to cram in a full game project within a month. A lil stressed. Thanks anyways
@aaron916
@aaron916 9 жыл бұрын
its telling me that the box2d ant be imported, arent they supposed to be in the lirbaries we attached to the buildpath in the first vid?
@MuresanVladMihail
@MuresanVladMihail 10 жыл бұрын
Who do you think would win between box2d and nape in terms of performance?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
I didn't even know what Nape was so I searched around for a bit. It seems Nape is made and optimized for AS3, and the Box2D port to AS3 isn't as good. So if you're going for flash games, better go with Nape.
@Icohedron
@Icohedron 10 жыл бұрын
I have exactly the same code but I kept "fdef.restitution = 1f;" is it normal for the box to now be gaining more height after every bounce? It's bouncing off the screen right now.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Yes. Someone else mentioned it and that's the way Box2D behaves apparently.
@thevioletmasquerade
@thevioletmasquerade 10 жыл бұрын
For some reason the com.badlogic.gdx.physics package is not included in the gdx.jar file of the latest nightly libgdx build I downloaded. I tried both nightly builds but it was still missing.
@Quaid2k
@Quaid2k 10 жыл бұрын
Hi Mike, I'm still having problems with the bouncing box shape. If I set to world.step(1 / 60f,1,1) as you suggest, it quickly bounces off screen after about 4 / 5 contacts with the ground. public void update(float dt) { world.step(1 / 60f, 1, 1); }; And, dt isn't being used anymore? If I set to world.step(dt, 1, 1) it remains on screen when bouncing but not consistent. I've check through all my code, it looks fine.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Don't use dt. It's variable now and using a variable timestep will make Box2D behave inconsistently as you can see. dt is for all non-Box2D related things. Tell me exactly what is happening. The box starts off over the platform, and it falls, and when it bounces off the platform, it just rockets up out of the screen?
@Quaid2k
@Quaid2k 10 жыл бұрын
ForeignGuyMike The box drops, hits the ground platform.. On each iteration the box gets a little higher and eventually goes off screen.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Quaid2k Try using higher accuracy in the simulation. I didn't realize I used that. world.step(1 / 60f, 6, 2);
@Quaid2k
@Quaid2k 10 жыл бұрын
ForeignGuyMike same result.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Quaid2k Send me your project.
@Broockle
@Broockle 7 жыл бұрын
So, what exactly are the advantage of making a game using LibGDX instead of using let's say Unity 2D which supplies a lot more visual aids and requires a lot less programming. Does unity require more performance than LibGDX?
@ForeignGuyMike
@ForeignGuyMike 7 жыл бұрын
Broockle I think you just answered your own question there. I can't really comment since I haven't used Unity, but I suppose you need a beefier pc for it
@Broockle
@Broockle 7 жыл бұрын
I meant for mobile development actually. I only heard of LibGDX today I didn't know it does more than mobile. But ye makes sense. I found Godot today as well, it looks more user friendly and similar to Unity. I can only program as well as the forum posts I find, the skills you display in this video are truly legendary. I can't follow any of it, I would only copy paste it and alter it as far as I can understand lol Nice series, it gave me an idea of how the workflow looks like with this engine. thx for the reply m8 ^^
@ayushsingh62
@ayushsingh62 10 жыл бұрын
You should really do a 3d game programming tutorial
@stolensus9594
@stolensus9594 5 жыл бұрын
For anyone struggling with newer versions of libgdx (using com.badlogic.gdx.physics.box2d.World) you need to add the jars under "extensions/gdx-box2d". Hope this helped some people
@ForeignGuyMike
@ForeignGuyMike 5 жыл бұрын
I highly recommend NOT creating a LibGDX project manually and use their project setup with gradle instead. github.com/libgdx/libgdx/wiki/Project-Setup-Gradle
@stolensus9594
@stolensus9594 5 жыл бұрын
@@ForeignGuyMike thanks for the tip! Definitely saved a lot of hassle later on. Spoke too soon, I guess :)
@theGreatDpunisher
@theGreatDpunisher 9 жыл бұрын
I copied ur code but i have no idea whats going on. My box2d wont work, its not moving... im using libgdx 1.6.5 in intelij.
@thevioletmasquerade
@thevioletmasquerade 10 жыл бұрын
I also tried a separate .jar file which did include the package, enabling me to finish inputting the code, but then I got missing source path errors. Any help is greatly appreciated.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Box2D has been moved to an extension. You need to include both the box2d jar and the box2d native jar.
@xucaen
@xucaen 9 жыл бұрын
I am doing something very similar to this. my box2d body is only 1 meter tall and my game world is 10m x 4m. Everything is being rendered perfectly. I implemented an input listener such that when I press the space bar I call body.applyForceToCenter(0, 600, true); I think 600 is a big number, but my box2d body only jumps about a centimeter and then floats very slowly down. my gravity is (0, -9.81f). I know I missed something but can't for the life of me see what it is. I am stumped.
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
I don't really know much about physics. I mean, you can try to calculate it yourself. 600 kg m/s² on a 1m² box with a mass of something and 9.81m/s² gravity.
@xucaen
@xucaen 9 жыл бұрын
I don't know, I just set the upward force to 99999 and the density to 113 (about 250 lbs and it floats like a feather. somehow the scale must be off...
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
***** You mean it seems like it's moving in slow motion? You're using a scaled camera right? What are your camera dimensions
@xucaen
@xucaen 9 жыл бұрын
OMG it was the stupidest thing but I just didn't see it. I had also added code to set the linear velocity when I press left and right arrow keys. However, when the keys are not pressed I was setting linear velocity to zero. That is messing up the upward (and downward) motion. as soon as I removed those lines of code, my jumping started working as expected. Feel free to chastise me as you will.
@xucaen
@xucaen 9 жыл бұрын
***** so it turns out you can't use applyForceToCenter and setLinearVelocity at the same time. I'm going to forget about using box2d and just code my own movement routines. Thanks for your help.
@XrwXX
@XrwXX 10 жыл бұрын
Hey i have one question , so basically i did everything in your tutorial, but when i try to launch it for android emu or android device the collision not working , the falling box go throw the static box , maybe you know hot wo fix it ?
@XrwXX
@XrwXX 10 жыл бұрын
Btw i'm using libgdx to create project
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
The only way I see that happening is if: 1) The fixtures are in the same body 2) The fixtures are sensors 3) The fixtures are filtered out of collision
@AmPProductionzz
@AmPProductionzz 10 жыл бұрын
Your videos are awesome entertaining and educational, you should definetly make a 3d game tutorial
@FaTalCubez
@FaTalCubez 10 жыл бұрын
It's not as easy as it sounds. Since all of his tutorials are in 2D, chances are he hasn't worked with 3D that much. BUT, since he is pretty smart, I'm sure he could figure it out. I just wouldn't expect him to make tutorials anytime soon unless I'm completely off about him not knowing 3D. I'm just making an educated guess :P
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
I did take an OpenGL course where we did 3D graphics. I wasn't really into it, and I forgot most of it already anyway.
@shawkenton5247
@shawkenton5247 10 жыл бұрын
The code works perfectly fine. But I have a conceptual doubt. You create an instance of Game in GameStateManager and an instance of GameStateManager in Game. Isn't this supposed to cause a stack overflow error?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
No... why would it?
@shawkenton5247
@shawkenton5247 10 жыл бұрын
ForeignGuyMike I mean if u create objects of classes from within eachother won't there be recursion?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Shaw Kenton They are only created once, and given a reference to each other. This does *not* create new instances: private Game game; public GSM(Game game) { this.game = game; }
@shawkenton5247
@shawkenton5247 10 жыл бұрын
ForeignGuyMike Oh thanks! Sorry I got confused. Great tuts btw :)
@solidive
@solidive 10 жыл бұрын
Wouldn't multiplying your world's gravity by PPM get you the same result visually ? (i'm new to Box2D so i'm not sure if that's acceptable : p)
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
With Box2D, it's best to keep things to scale. The Box2D manual recommends: *"Box2D has been tuned to work well with moving objects between 0.1 and 10 meters. So this means objects between soup cans and buses in size should work well. Static objects may be up to 50 meters big without too much trouble."* And multiplying gravity to almost 1000m/s/s is insane and would most likely cause calculation problems.
@solidive
@solidive 10 жыл бұрын
ForeignGuyMike Ow ok that makes sense, thanks :)
@Majskolvenz
@Majskolvenz 10 жыл бұрын
Wouldn't it be good for performance if you made the Box2D unit ratio a power of two? So instead of 100 you could use 128 and then use a bit operator to shift the bits 7 places when you need to scale up or down.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Sure you could do that. But is it necessary? I always find premature optimization pointless. If it's not lagging, then it ain't broke.
@CakeStak
@CakeStak 10 жыл бұрын
ForeignGuyMike This is such a good point. I always usually prematurely optimize, glad you said that.
@1ut4d3l1ll3
@1ut4d3l1ll3 10 жыл бұрын
I have a problem, my libGDX doesn't contains "com.badlogic.gdx.physics.box2d.World", does not contains any "physics" at all. I just downloaded the latest one, libgdx-nightly-20140916.zip Anyone could help me? PD: The project contains all the necessary gdx files and the referenced libraries
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Box2D has moved to extensions. You need to add those Box2D jars. But I recommend setting up your project with the Gradle setup.
@1ut4d3l1ll3
@1ut4d3l1ll3 10 жыл бұрын
ForeignGuyMike Thank you very much Mike. It works fine. ;)
@chrislerlaid242
@chrislerlaid242 9 жыл бұрын
Since libgdx doesn't support gl10 anymore. I used gl20, but this code Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); is not recognized. The GL_COLOR_BUFFER_BIT is not included in the list.
@chrislerlaid242
@chrislerlaid242 9 жыл бұрын
Chrisler Laid I figured out, I made the wrong import. import org.lwjgl.opengl.GL20 ; Instead of: import com.badlogic.gdx.graphics.GL20;
@odo432
@odo432 9 жыл бұрын
Given that 100 pixels = 1m couldn't you instead just type in metres and multiple by PPM instead of dividing? EG. Instead of 160 / PPM you could do 1.6f * PPM. That way you wouldn't need to create a new camera which I believe is resource intensive.
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
You mean replace 160/PPM with just 1.6f. I guess you could do that if you wanted, but if I needed to change my conversion rate, it would be a hassle to go through all the values individually when I can just change PPM. I haven't heard camera is resource intensive. The only thing I heard that you shouldn't have more than one of is the SpriteBatch.
@odo432
@odo432 9 жыл бұрын
No sorry. I meant 160 / PPM with the new camera you created to increase size (as it was tiny) is the same as 1.6f * PPM using the default 'cam' camera. 1.6f being 1.6m in the game which is multiplied by PPM which is the amount of pixels which represents the length of 1m in the game. Hope that makes sense. :)
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
Mat O Box2D is a physics simulation engine. It runs well within "normal" ranges, and behaves unpredicatbly with abnormal sizes. It uses meters as its unit. If I understand what you're saying correctly, what you're asking is putting Box2D outside of its comfort zone. Take the falling box Body for instance. It's 10/PPM x 10/PPM, or 0.1m x 0.1m. You're asking me to change the box size instead to 0.1*PPM x 0.1*PPM, or 10m x 10m just to fit in the normal camera. Unfortunately, a box that size might not behave very normally.
@odo432
@odo432 9 жыл бұрын
Yes. I noticed when I was testing it that my box did not fall as fast as yours. I also noticed that if you upped the gravity to insane levels (like 100+) and applied perfect bounce (1) it acted abnormally. Wonder if it's just a limitation of the physics engine? Either way, it's fun playing around with and performing trial and error runs.
@larssonk22
@larssonk22 10 жыл бұрын
I've been reading that it's not a good idea to use the pixel size for dimensions. I'm can't find the alternative method of creating your own unit size.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
This is a pixel game, so I want it to look pixelated. If you want, I think LibGDX has a feature that allows to convert pixels.
@larssonk22
@larssonk22 10 жыл бұрын
ForeignGuyMike Hi thanks for replying, I have tiles 60px by 60px, so I'd like to use that as my unit ie. 60px by 60px= 1 unit, I just don't know how to set up the camera to do so :(
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
TheDonBarracuda Ohhhhh, I thought you meant independent screen density pixels. You're talking about Box2D right? Yeah, I convert pixels to meters.
@larssonk22
@larssonk22 10 жыл бұрын
ForeignGuyMike I'm not using box2d either. I'm making a simple tetris game using arrays, but things seem to be over complicated when using pixels for dimensions. And cause problems when porting to different devices.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
TheDonBarracuda Hmm, not really sure :\
@meykilim
@meykilim 9 жыл бұрын
I'm having trouble with: import com.badlogic.gdx.physics.Box2DDebugRenderer; import com.badlogic.gdx.physics.World; with the "com" any idea what it might be?
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
João Pedro Bastos Nope
@Nicolas3738
@Nicolas3738 9 жыл бұрын
+João Pedro Bastos Im having the same problem and I don't know why
@HarmanjeetKhangura
@HarmanjeetKhangura 8 жыл бұрын
Edit: This explanation is wrong as pointed out by ForeignGuyMike in comment below.. +João Pedro Bastos +Nicolas3738 I don't know if you still need this answer but you are not supposed to add ; (Semicolon) at the end of import statements.. Instead of import com.badlogic.gdx.physics.Box2DDebugRenderer; import com.badlogic.gdx.physics.World; write import com.badlogic.gdx.physics.Box2DDebugRenderer import com.badlogic.gdx.physics.World
@ForeignGuyMike
@ForeignGuyMike 8 жыл бұрын
Harmanjeet Khangura This is 100% false.
@HarmanjeetKhangura
@HarmanjeetKhangura 8 жыл бұрын
Sorry mate.. My bad. I mixed Objective C and Java.. I have been doing self imports for so long, I lost track of it..
@din8640
@din8640 10 жыл бұрын
Since the Box2D has become and extension, how can I import Box2D now on this existing project?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Use the LibGDX setup to create your projects.
@NahroGamer
@NahroGamer 9 жыл бұрын
Kostas Kadoglou update the build.gradle dependancies
@KirtanShahU
@KirtanShahU 8 жыл бұрын
I did b2dCam = new OrthographicCamera(); b2dCam.setToOrtho(false, Game.V_WIDTH / PPM, Game.V_HEIGHT / PPM); but it still shows my fixtures as dots. (PPM is 100). Any suggestions?
@ForeignGuyMike
@ForeignGuyMike 8 жыл бұрын
+Kirtan Shah Are you rendering the Box2D debug lines with the b2dCam?
@KirtanShahU
@KirtanShahU 8 жыл бұрын
ForeignGuyMike yes, this is my render line: b2dr.render(world, b2dCam.combined);
@KirtanShahU
@KirtanShahU 8 жыл бұрын
+ForeignGuyMike Also, if the b2dCam still doesn't work, can I just multiply the gravity by PPM?
@ForeignGuyMike
@ForeignGuyMike 8 жыл бұрын
Kirtan Shah No. Small fixtures need small cameras. If the cameras are fine, your fixtures are messed up.
@KirtanShahU
@KirtanShahU 8 жыл бұрын
ForeignGuyMike Ok, but my fixtures are fine as well. I have fdef.shape = shape, where shape is a PolygonShape and I put the same values in the tutorial and divided them by PPM
@n0MC
@n0MC 9 жыл бұрын
very nice video, well explained
@grassinog2803
@grassinog2803 10 жыл бұрын
Hey, great tutorial but I get an Error: BodyDef def = new BodyDef(); def.position.set(160, 120); Multiple markers at this line ; - Syntax error on tokens, delete these tokens; - Syntax error on token(s), misplaced construct(s) def.type = BodyType.StaticBody; Syntax error on token "type", VariableDeclaratorId expected after this token Thanks in advance :)
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
I don't know. You're probably using the wrong punctuation somewhere.
@Lumai0
@Lumai0 10 жыл бұрын
After the setting new size ratio, nothing shows up :/ My code is nearly identical to yours. The V_WIDTH and V_HEIGHT are renamed to WIDTH and HEIGHT.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
You have the b2dCam set up? Since the Box2D objects are PPM times smaller, the b2dCam also should be PPM times smaller. b2dCam = new OrthographicCamera(); b2dCam.setToOrtho(false, WIDTH / PPM, HEIGHT / PPM); Then use that camera for rendering. b2dr.render(world, b2dCam.combined);
@Lumai0
@Lumai0 10 жыл бұрын
I made a stupid mistake inside B2DVars.java, I set PPM as an int instead of a float :/ It's fixed now, thanks for the help. Also, great tutorial series :)
@emredemirsatan4897
@emredemirsatan4897 10 жыл бұрын
Lumaio Me too, thanks!!!
@bvisonl
@bvisonl 10 жыл бұрын
Lumaio Also here... thanks mate
@WurstschneideBrot
@WurstschneideBrot 4 жыл бұрын
Then WHY does box2d use these units when most people change these to like 100 PPM ??? Why can't be that impleneted as a 1-liner? Like SetPPM It looks horrible when u divide it everywhere with this constant...
@ForeignGuyMike
@ForeignGuyMike 4 жыл бұрын
You know what? thats actually an interesting question. I have one idea, not sure how well it will work though. One thing you can try is to make subclasses of some of the Box2D classes and like you said, have some kind of setPPM function. Then, override all those position, vector, etc methods to use the PPM. It's a lot of work I think, but itll make it easier in the long run.
@shivakudikala6460
@shivakudikala6460 9 жыл бұрын
How you kept a Package in a Package
@biswasl
@biswasl 10 жыл бұрын
For some reason even after I have done clear screen, its still not rendering properly. Any specific reason for this?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
What does "not rendering properly" mean?
@biswasl
@biswasl 10 жыл бұрын
Thanks for replying Mike. It is still showing the trails of the moving box. Once it rests on he ground object, the application slows down and eventually hangs.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Biswas Lamichhane Show me your Play.java
@biswasl
@biswasl 10 жыл бұрын
ForeignGuyMike Nevermind, I completely re - wrote Play.java and its working now. Couldn't find the issue though. Thanks for the amazing tutorials Mike.
@ShangDamaTsung
@ShangDamaTsung 3 жыл бұрын
Wow Great tutorial... !
@justinmcdonald2502
@justinmcdonald2502 8 жыл бұрын
im getting null pointer errors when i try to render i cant figure out why
@ForeignGuyMike
@ForeignGuyMike 8 жыл бұрын
+Justin McDonald No joke. Null pointers are one of the easiest bugs to fix. Look at the exception that being thrown. It straight up tells you which class and which line of code is throwing the exception. In Eclipse, you can even click on the line in the exception message for convenience and it'll bring you to the exact line that has a null issue. Find out why it's null, and then how to make it not null.
@michaelalvarez8937
@michaelalvarez8937 10 жыл бұрын
Where did you learn all this?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
google and box2d manual.
@appukumar1908
@appukumar1908 7 жыл бұрын
how a body shoot from a fixed point and rotate through angle..this physics body collide with the wall. like bubble shooter game
@thevioletmasquerade
@thevioletmasquerade 10 жыл бұрын
Works now, thanks.
@zoltanacs90
@zoltanacs90 10 жыл бұрын
ForeignGuyMike Hi, for some reason I am not able to import the com.badlogic.gdx.physics.box2d.Box2DDebugRenderer class. Can you help me? Netbeans writes me, that package com.badlogic.gdx.physics.box2d does not exists. :S
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Box2D moved to an extension. You can find it in the extensions directory. I suggest using Gradle to set up your projects.
@zoltanacs90
@zoltanacs90 10 жыл бұрын
ForeignGuyMike thx a lot!
@chuckita
@chuckita 8 жыл бұрын
how do you download box2D?
@TheFatSmurfs
@TheFatSmurfs 9 жыл бұрын
ForeignGuyMike Hey man i've been doing research on javascript anyway this time i have a real error and its the fact that world can't be resolved to a type and i cant import i can only make a class called World.
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
You need to have the Box2D libraries.
@TheFatSmurfs
@TheFatSmurfs 9 жыл бұрын
ForeignGuyMike i do.... im positive i even checked
@ForeignGuyMike
@ForeignGuyMike 9 жыл бұрын
TheFatSmurfs The *can't be resolved to a type* error means the program cannot figure out what type of object it is. In this case, the game has no idea what the World object is. World is an object that's part of the Box2D libraries. You need those libraries on your build path, and you need to import those libraries. Then you can use it.
@TheFatSmurfs
@TheFatSmurfs 9 жыл бұрын
ForeignGuyMike yea i know, that's why i cant understand this error because in the 1st video i imported everything i needed to import... any specifics for a certain library? because i notice its in the box2d bad logic library and i've imported things from that library.... that's why i cant understand this error
@aaron916
@aaron916 9 жыл бұрын
ForeignGuyMike are the box2d libraries contained within the ones in the build path from the first vid? or do you add them in after?
@SzahMatt
@SzahMatt 9 жыл бұрын
All guys who have problem with World class. U have to download the source code under the movie, and replace yours glx.jar file with this downloaded. I dont know why, but in the newest libs from glx we not find .physics.*
@МарияПостникова-д5и
@МарияПостникова-д5и 6 жыл бұрын
thank you very much! I also couldn't find physics in the newest package
@OyemeLife
@OyemeLife 10 жыл бұрын
Thank you!!!
@Htrom1
@Htrom1 10 жыл бұрын
Aha that's kinda funny that's the first thing you say next video
@Schlimbinger
@Schlimbinger 5 жыл бұрын
stabil
@sombraeterna99
@sombraeterna99 10 жыл бұрын
World doesnt exist, i dont know whats wrong
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
... you didn't make it?
@sombraeterna99
@sombraeterna99 10 жыл бұрын
ForeignGuyMike the import physics.World doesn exist
@CoLinearProductions
@CoLinearProductions 10 жыл бұрын
8:30
@UGCjezus
@UGCjezus 10 жыл бұрын
First, thank you for the tutorial. Second I have run into the same problem as @Justin Mickelson. Here is the stack trace. Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) Caused by: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D at org.jbox2d.common.Timer.now(Native Method) at org.jbox2d.common.Timer.reset(Timer.java:35) at org.jbox2d.common.Timer.(Timer.java:31) at org.jbox2d.dynamics.World.(World.java:587) at org.jbox2d.dynamics.World.(World.java:158) at org.jbox2d.dynamics.World.(World.java:154) at org.jbox2d.dynamics.World.(World.java:145) at com.badlogic.gdx.physics.box2d.World.(World.java:61) at states.Play.(Play.java:17) at handlers.GameStateManager.getState(GameStateManager.java:34) at handlers.GameStateManager.pushState(GameStateManager.java:44) at handlers.GameStateManager.(GameStateManager.java:20) at main.Game.create(Game.java:34) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Box2D is longer part of the standard gdx jar. If you're using the latest LibGDX, you can find the Box2D jars in the extensions folder. Also, I suggest you use Gradle to set up your project.
@UGCjezus
@UGCjezus 10 жыл бұрын
Mike I have already added all three jars in the extensions folder prior to writing the message above. I did not use Gradle to set up the project. I will do that, however I did read all comments on this page before posting. I don't want to waste your time with stupid questions. I will use Gradle to resetup the project. Thank you for your assistance.
@LukTarPL
@LukTarPL 10 жыл бұрын
ForeignGuyMike Gardle is so heavy. URL to box2d is libgdx.badlogicgames.com/nightlies/dist/extensions/.
@c4v2
@c4v2 10 жыл бұрын
too bad that box2d lack of Javadoc :(
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Well, you don't really need it. There is already a manual. It's in c++ but the LibGDX Box2D JNI pretty much uses the same method and class names as the original c++. You should be able to easily take the c++ code from the manual and turn it into Java. For example, in section 2.3 of the manual, it shows you how to create a Body in c++: b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(0.0f, 4.0f); b2Body* body = world.CreateBody(&bodyDef); The simple translation to LibGDX Box2D is: BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody; bodyDef.position.set(0.0f, 4.0f); Body body = world.createBody(bodyDef); Yeah, it's not completely the same method and class names. Box2D classes have the b2 prefix to try to keep it from messing up namespaces, and the methods are camelcase, but you can always use Eclipse Intellisense (the little box that appears when you type in some code to help you finish. You can also activate it with ctrl + space). And you can ignore the pointer stuff (& and *). If it's a little hard to translate, you can use google or: github.com/libgdx/libgdx/wiki/Box2d
@c4v2
@c4v2 10 жыл бұрын
ForeignGuyMike You are right but this is more about the comfort of writing the code. I like it a lot when my IDE tells me exactly what the function doeas and what the argument stands for :)
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
c4v2 Yeah I don't really need that stuff. You can include the source code for jars in Eclipse project settings. Intellisense will give the API documentation for the classes and methods.
@แอนจัง-ฐ4ผ
@แอนจัง-ฐ4ผ 6 жыл бұрын
You ,give me source code
@hobbles4u
@hobbles4u 10 жыл бұрын
For some reason I cant import box2D was it included with libGDX?
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
www.badlogicgames.com/wordpress/?p=3412 Specifically the 5th point
@hobbles4u
@hobbles4u 10 жыл бұрын
Is adding it the same way I did the rest if libGDX correct I got to the part where you ran the box and I am getting an exception... Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) Caused by: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D at org.jbox2d.common.Timer.now(Native Method) at org.jbox2d.common.Timer.reset(Timer.java:35) at org.jbox2d.common.Timer.(Timer.java:31) at org.jbox2d.dynamics.World.(World.java:587) at org.jbox2d.dynamics.World.(World.java:158) at org.jbox2d.dynamics.World.(World.java:154) at org.jbox2d.dynamics.World.(World.java:145) at com.badlogic.gdx.physics.box2d.World.(World.java:61)
@hobbles4u
@hobbles4u 10 жыл бұрын
Alright I just decided to get the older libGDX so its all good now.
@ForeignGuyMike
@ForeignGuyMike 10 жыл бұрын
Justin Mickelsen You should really avoid using older versions. LibGDX Box2D is a JNI for the native Box2D. You need to also add the Box2D natives jar.
@hobbles4u
@hobbles4u 10 жыл бұрын
ForeignGuyMike Alright I gave it another shot and I got it working this time. I created a new project and just brought in everything from the old one and added all the libs again. Not to sure why but it is working this time. Thanks a lot man, now to continue forward with this. Great tut by the way.
LibGDX Box2D Tiled Tutorial - Block Bunny - Part 7 - Box2D Sprites
19:02
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 38 МЛН
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 11 МЛН
Mom had to stand up for the whole family!❤️😍😁
00:39
Это было очень близко...
00:10
Аришнев
Рет қаралды 2,3 МЛН
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 719 М.
Writing a game the hard way - from scratch using C. #1
34:20
NCOT Technology
Рет қаралды 148 М.
MP3 CDs: a hybrid "format" that never existed, yet was surprisingly common
34:18
Technology Connections
Рет қаралды 167 М.
Why I'm Glad I Didn't Use Unity
5:34
DaFluffyPotato
Рет қаралды 614 М.
Mouse Cursor History (and why I made my own)
15:09
Posy
Рет қаралды 2,7 МЛН
Solving Wordle using information theory
30:38
3Blue1Brown
Рет қаралды 10 МЛН
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 38 МЛН