Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>for(CCSprite *s in collection) { if(CGRectContainsPoint([s boundingBox], location)) s.position=ccp(location.x,location.y); } </code></pre> <p>Since all your sprites are in the same location, the above code is moving all sprites in that location.</p> <pre><code>for(CCSprite *s in collection) { if(CGRectContainsPoint([s boundingBox], location)) { s.position=ccp(location.x,location.y); break; } } </code></pre> <p>The above code will break out of the loop once the first sprite is detected, hence should only move the first sprite in the array.</p> <p>Not sure if this is exactly what you want, but hope this helps.</p> <p>----edit</p> <p>Personally what I would do is have a instance variable for a sprite.</p> <pre><code>CCSprite * touchedSprite; </code></pre> <p>and do the following...</p> <pre><code>-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch=[touches anyObject]; CGPoint location=[touch locationInView:[touch view]]; location=[[CCDirector sharedDirector]convertToGL:location]; location=[self convertToNodeSpace:location]; for((CCSprite * sprite in collection) { if(CGRectContainsPoint([sprite boundingBox], location)) { touchedSprite = sprite; p = sprite.position; break; } } } -(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"count:%i",[collection count]); UITouch *touch=[touches anyObject]; CGPoint location=[touch locationInView:[touch view]]; location=[[CCDirector sharedDirector]convertToGL:location]; location=[self convertToNodeSpace:location]; touchedSprite.position = location; } -(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { touchedSprite.position = p; } </code></pre> <p>i didn't test the code so i am not sure if it will work just by copying and pasting, but i think this will give you the right idea. There are obviously other ways of doing this, but i think its the simplest if you are to do bunch of stuff to the sprite that is being touched.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload