42 videos
238 minutes
To create this Fixture, we must use the following. As we have created from the Body World, to create the Fixture we have to do from the Body. We have a method called createFixture to create a fixture, and here are two options: either use FixtureDef, or use Shape and Density. I tell you one thing, they really are the same. FixtureDef has a lot of data about the Fixture, as what form, what size, what is its density ...
many properties. We can do so, or we can directly pass the Shape, the way we want to have, as a form rectangular or circular. Or I want to even pixels that should have, or should have vertices. And also pass density. Frankly, since only want to create a box, I will pass a Shape. It will be a rectangular box, which can define PolygonShape to indicate that you have a polygonal shape.
If we created a circle, Polygon would not help, because the circles are special, need their own CircleShape. But a polygon is sufficient here. And now I have to say the dimensions we want to have the way. For example, setAsBox. Here we tell the width and height that we want the minijoe. Now you say, 'Okay, so if I want to occupy 80 pixels wide and high, I'll spend 80, 80'. Error! Why? Because Box2D works in meters. Be not can
ask that you create a body of 80 meters high! It's higher than some apartment buildings! It has no logic, we would create Godzilla! Box2D works in meters so we need something more realistic. Not only because it is not realistic to have a body of 80 meters: the physical is going to break with very high objects. How you can measure Minijoe? I do not know, really, because it does not exist in real life. But I'll give it a dimension of 1 meter.
A lady box, not bad. You will say it is small, but do not worry, because we can then scale. Be realistic. I repeat that it is a mistake makes many people at first, trying to create bodies of 300 pixels high, forgetting that they are not pixels but meters and create a body of 300 meters height is illogical. When we created the Shape, create the Fixture using the Body for this purpose, with the Fixture Shape and density such as 1,
because it goes without saying anything more. That done, yes, we must make a dispose (). And, do not have to keep the Shape later because the we have used so right here at the show () I make a dispose (), and you're done. With this we have created the body. Let's see the action and Fixture the Body in action. What a thrill, right? So little! If you can not see. Okay, why? Because we are creating a camera that has 640 pixels by 480 pixels
high. Or 640x360. I do not remember the numbers, but many pixels. And the body is very small now, so we can not pass the camera such large dimensions. We need to pass something smaller.
About the Author
Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.