简体   繁体   中英

Cocos2D : How to detect that I moved a sprite in a specific zone?

2 things I'd like to do with cocos2D : 1) set a random board based on 6 png files (like a 6 tiles boardgame) 2) be able to move a sprite/pawn with my finger and detect on which tile the sprite/pawn was moved and trigger a specific action depending upon which tile is under my sprite/pawn...

any code examples ??? cheers,

Tibi.

one way you could do it would be to create an array of 6 x/y coordinates, one for each of the locations of the tiles. you could use these to move your pawns to and to test if they are in these locations, ie

if (pawn.position.x == sotoredLoc.x && pawn.position.y == sotoredLoc.y)
[pawn runAction];

type thing...

for the random part you might want to search for how to create an array of unique random numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM