我需要一种更快的方法来写这个。
if(sprite1.position.x==33 && sprite1.position.y==33){
// some code goes here to add sprite1 to an array object at index 0
}
if(sprite2.position.x==33 && sprite2.position.y==33){
// some code goes here to add sprite2 to an array object at index 0
}
if(sprite3.position.x==33 && sprite3.position.y==33){
// some code goes here to add sprite3 to an array object a index 0
}
if(sprite4.position.x==33 && sprite4.position.y==33){
// some code goes here to add sprite4 to an array object at index 0
} ....e.t.c
if(sprite1.position.x==33 && sprite1.position.y==97){
// some code goes here to add sprite1 to an array object at index 1
}
if(sprite2.position.x==33 && sprite2.position.y==97){
// some code goes here to add sprite2 to an array object at index 1
}
我有 4 个数组,每个数组包含 4 个精灵。
我有 16 个点和 16 个精灵。每个精灵都有一个随机点,所以我必须检查每个精灵是否等于该点,并且每个精灵只有一个点。然后将其添加到数组中。我从索引 0 处的对象的数组中调用该对象,因为我确定索引 0 处的对象是一个精灵,它等于 point1,即 (33,33)。sprite 将在 cctouchmoved 中调用,因此我可以在该点移动 sprite,但数组是这样我可以移动一列 sprite,因为我知道它们都在正确的位置。现在我的问题是输入所有这些很长我必须做一个循环或其他东西。