42 videos
238 minutes
Let's see now how to create that ground. We have seen how to create a body and a fixture, so it should not be anything new for now. I create a sueloBody and ... why is the gray variable? Because I forgot to make sure dispose. I tell you now: to make a dispose a fixture, you have to call the Body, and as with World, you will have a method called destroy to destroy a fixture. He has forgotten me, I would have to
I have said before. I think the fixture ground, and since I am here I will try to remove it and put it here. To create the fixture and the body of I usually do the same. createBody, createSueloBodyDef ... I know that Spanglish is not the best, but good. We create the definition of soil, which is similar to the body of Joe, but now let's create a StaticBody. By default the bodies are static unless we change it so easy. We are going to
give a position, and the position that I will give is 0, -1. Now I will explain why that -1. Finally I create the fixture now we have it. I create a PolygonShape, as in the other case. I want to give a rectangular long to fit along the entire level form, and cut high to avoid occupy too upright site. For example, I'll give as size 1 kilometer wide and 2 meters high. The camera will zoom so you have not seen
below ground that there is nothing. But not enough to put 1000 and 2 because I have tricked before: we do not pass here above, but we pass the highest average and medium width. That is, that all this is multiplied by 2. Why does this happen? Let's go back and I will Skitch drawing. When we are creating a Body, Suppose circular or rectangular in this case, and give you our position, the position that we will define the center of gravity will be here.
So if we body.position.set, we define where the point is placed. And we measured the dimensions give dimensions where this is placed and this. But with (1.1), will mean that average width is 1 and high average is 1, so total height will be w = 2, h = 2. I've already changed the setAsBox of Minijoe 0.5 because otherwise we would create a character of 2 meters wide and high. So if I want to create a floor of 1 km will I have to give actually 500 meters,
and to give 2 meters high, I must give you a 1. Now it makes sense why the soil is at -1. If that point defines the center, now the top the soil is 0, and that will come in handy because the body of Joe and everything else will be around y = 0, and be well. In this case, all that remains is associate the fixture with the Body. Do not forget to use the correct body. I think the shape, density ... Remember to do a dispose to no longer use the Shape
because we do not need more. Now, if I run, this floor will see that appears, and that when he plays, stops falling. You will have set that at the time the falling has a different color, when the box on the floor. See if ... you see is pink, and suddenly turns gray? That's because Box2D detected which it is at rest, and no longer have to upgrade more that body. Do you remember that when creating the World we told him doSleep be True? Here is the result.
If Box2D detects that it is at rest, and do not have to act on it any force, so stop acting upon it. In the case of StaticBody, and not have to process any force, even change color, and in fact has another color, green, to indicate that it is a body on which not affect forces. But despite not having forces, continues to interact in shares. In fact all collisions generate an event that can treat
for things like jumps or collisions with enemies. Now all that remains is to fix the camera, because as you see it is a bit far. It would be good that now we have what our taste a little zoom would make so it is not bad. So what we'll do is, finally, give the dimensions that had to have. As you are going to see now, is not going to look good, so I do translate type operation, because soil
It is too high. I'll lower it a bit with the translate method, which has nothing to do with the translation into Spanish, what it does is move the camera to move the floor below. Thus no longer you are going to see both the ground, as he has around him. And this is taking shape of Geometry Dash ... I say Jump Do not Die, what's that Geometry Dash? Obviously the Minijoe must be left to not look like the scenario we take over,
but this is practical.
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.