4 ms·
Can someone explain this to me? var sprite = cocos.nodes.Sprite.create({file: '/resources/ball.png'}); And then it's assigned to a box2d object: var
by mrspeaker 15y ago
Can someone explain this to me?
var sprite = cocos.nodes.Sprite.create({file: '/resources/ball.png'});
And then it's assigned to a box2d object:
var bdy = world.CreateBody(bodyDef);
bdy.sprite = sprite;
How does box2d know how to deal with a cocos2d sprite object?
- DanielRibeiro 15y agoIf I'm not mistaken, Box2d doesn't. This is where Cocos come to the rescue, enhacing things and making the glue between the physic world and the image world.
- Raticide 15y agoThat's just to keep a reference to the sprite along with the body. There's no real magic to it. Later in the 'update' function it loops over each body and updates the attached sprite: https://github.com/ryanwilliams/cocos2d-demo-box2d/blob/master/src/main.js#L62 https://github.com/ryanwilliams/cocos2d-demo-box2d/blob/mast...