开发者

How do I know when my sprite collides with an object?

Sorry, My english isn't very good.

I have a quiet sprite with a map moving in the x-axis to the left, giving the impression that sprite run to the right.

_tileMap runAction:[CCMoveBy actionWithDuration:80.0 position:ccp(-2000,0)]];

My tilemap is set to true propiedates Collidable with programa "Tiled" with a "Tileset> properties>" "Collidable" set to "True"

Map position is known to me at all times with _tileMap开发者_JS百科.position.x

How do I know when my sprite collides with an object?

Thanks!!


Cocos2D won't do this for you, you need to calculate any collisions yourself.

If you want the simplest possible case, just take the position of your sprite, translate it into a tile map coordinate and then get the properties for that tile. If there is a collide-able property set to true then your sprite has hit collision and you need to code up the appropriate response.

This assumes that only the center point of your sprite will ever collide, you will want to define more points within your sprite to test.

A simpler approach may be to use Box2D or another 2D physics system and define collision shapes for your sprites, then you can get callbacks when collision occur.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜