Cocos2D:如何检测我在特定区域中移动了一个精灵?

时间:2021-08-10 10:04:57

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...

我想用cocos2D做的2件事情:1)根据6个png文件设置一个随机板(比如6个瓷砖游戏)2)能够用我的手指移动精灵/棋子并检测精灵/哪个瓦片/ pawn被移动并触发一个特定的动作,具体取决于我的精灵/ pawn下面的哪个tile ...

any code examples ??? cheers,

任何代码示例???干杯,

Tibi.

提笔。

1 个解决方案

#1


0  

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, i.e.

你能做到的一种方法是创建一个6 x / y坐标的数组,每个坐标对应一个瓷砖的每个位置。您可以使用这些来移动您的棋子并测试它们是否在这些位置,即

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.

对于随机部分,您可能希望搜索如何创建唯一随机数组。

#1


0  

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, i.e.

你能做到的一种方法是创建一个6 x / y坐标的数组,每个坐标对应一个瓷砖的每个位置。您可以使用这些来移动您的棋子并测试它们是否在这些位置,即

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.

对于随机部分,您可能希望搜索如何创建唯一随机数组。