Hey, I've gone through a couple of tutorials and seen some nice stuff and I'd like to recreate it.
Here, I've taken the video tutorial, and applied the code from it (updating the CreateStaticBody to just CreateBody as version 2.0.1 doesn't have Static or Dynamic functions).
So, I've gotten my floating static rectangle.
Now, I've worked out (because we have no CreateDynamicBody and only CreateBody) that if you change the density and restitution (as if elasticity isn't a hard enough word) it can become dynamic.
So, I've made a function to make three simple dynamic circles. And they collide with everything in my world including my floating rectangle. GREAT.
Now, I've seen in another older tutorial you can use the userData to equal to sprites in your library class.
So I've made a library object, set my userData to my library object and addChild() my userdata. But now I need to update the co-ordinates of my userData along with my Step function.
However, the older tutorial uses a different version of Box2D and throws compiler errors that say the properties no longer exist (most likely renamed).
Here is the code to update all the userDataSprites from the tutorial:
Now, this code throws me off. I'm used to using the for statement in your usual number state such as:
for (var i:int=0; i<10; i++)
How does a b2Body object in the second parameter equal true or false?
Any help understanding would be much appreciated.
And also the errors being thrown are bb.m_rotation, bb.m_position.x and bb.m_position.y. Is there another way to get these values to make it work?
Thanks for reading such a lengthy post.
Here, I've taken the video tutorial, and applied the code from it (updating the CreateStaticBody to just CreateBody as version 2.0.1 doesn't have Static or Dynamic functions).
So, I've gotten my floating static rectangle.
Now, I've worked out (because we have no CreateDynamicBody and only CreateBody) that if you change the density and restitution (as if elasticity isn't a hard enough word) it can become dynamic.
So, I've made a function to make three simple dynamic circles. And they collide with everything in my world including my floating rectangle. GREAT.
Now, I've seen in another older tutorial you can use the userData to equal to sprites in your library class.
So I've made a library object, set my userData to my library object and addChild() my userdata. But now I need to update the co-ordinates of my userData along with my Step function.
However, the older tutorial uses a different version of Box2D and throws compiler errors that say the properties no longer exist (most likely renamed).
Here is the code to update all the userDataSprites from the tutorial:
Code:
// Go through body list and update sprite positions/rotations
for (var bb:b2Body = myWorld.m_bodyList; bb; bb = bb.m_next) {
if (bb.m_userData is Sprite) {
bb.m_userData.x = bb.m_position.x;
bb.m_userData.y = bb.m_position.y;
bb.m_userData.rotation = bb.m_rotation * (180/Math.PI);
}
}// This is an extremely clever way to do this, and I suggest you copy it exactly in your own projects.
for (var bb:b2Body = myWorld.m_bodyList; bb; bb = bb.m_next) {
if (bb.m_userData is Sprite) {
bb.m_userData.x = bb.m_position.x;
bb.m_userData.y = bb.m_position.y;
bb.m_userData.rotation = bb.m_rotation * (180/Math.PI);
}
}// This is an extremely clever way to do this, and I suggest you copy it exactly in your own projects.
Now, this code throws me off. I'm used to using the for statement in your usual number state such as:
for (var i:int=0; i<10; i++)
How does a b2Body object in the second parameter equal true or false?
Any help understanding would be much appreciated.
And also the errors being thrown are bb.m_rotation, bb.m_position.x and bb.m_position.y. Is there another way to get these values to make it work?
Thanks for reading such a lengthy post.