Question

I need a quicker way to write this.

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
}

I have 4 arrays that hold 4 sprites each.

I have 16 points and 16 sprites. Each sprite has been give a random point so I have to check every sprite if it is equal to the point and each sprite has only one point. It is then added to an array. I call the object from the array at object at index 0 as i know for sure that the object at index 0 is a sprite that is equal to point1 which is(33,33). The sprite will be called in cctouchmoved, so i can move the sprite at that point but the array is so i can move a column of sprites as i know that they are all in the right positions. Right now my problem is typing all of that is very long do i have to make a loop or something.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top