Note that there are some explanatory texts on larger screens.

plurals
  1. POcocos2d for iPhone - Touch no longer works correctly after scale
    primarykey
    data
    text
    <p>I am rather new to using Cocos2d for iPhone and I am having an issue with touch locations. At the moment I am simply trying to touch and move a sprite on the screen, this works fine when the layer is unmoved as well as when I translate the layer (changing self.position in X direction in my case) however, when I scale my layer (example: self.scale = .5) the touch no longer moves the sprite. I have done a lot of forum searching/google searching and I think my issue has to do with my coordinate transforms (node space/world space etc.) But I am not 100% sure. I did notice that when I scale, if I click the location where the sprite would be without the scale, then I could move the sprite. This leads me to believe that my transforms are not taking the scale into account.</p> <p>Here is the coordinate transform code I am currently using to get touch locations:</p> <pre><code>- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [touches anyObject]; CGPoint location = [myTouch locationInView:[myTouch view]]; location = [self convertToNodeSpace:location]; location = [[CCDirector sharedDirector] convertToGL:location]; } </code></pre> <p>Here is the code that is checking if the location (same location variable as above) is touching a sprite, although I feel much more confident that this code is correct, who knows!</p> <pre><code>for (CCSprite *sprite in movableSprites) { if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) { NSLog(@"Woohoo, you touched a sprite!"); break; } } </code></pre> <p>Let me know if you need anymore information and thanks for reading!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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