0

I'm using Xcode with Cocos2d version 3.0.

I want to drag sprites around the screen. I've done so successfully using the following code:

(void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event 

{

CGPoint touchLocation = [touch locationInNode:self];

sprite1.position=touchLocation; 

sprite2.position=touchLocation; 

sprite3.position=touchLocation;

sprite4.position=touchLocation; 

}

However, sometimes the sprites stop moving after a second. It's not a lag, because they never catch back up with my movement. They just stop! If I let go and start moving my touch again, the sprites start moving fine again / sometimes do the 'freeze thing' again.

Is it a memory issue?

Ok, I'm sure it must be memory. I copied this code onto a simple game with hardly any sprites and it worked perfectly.

  • maybe the touch leaves [self boundingBox], in which case you will stop receiving the touchmoved events. – YvesLeBorg Sep 25 '14 at 17:03
  • Thanks for the reply Yves. I think the 'self' refers to the whole screen. Of course my finger doesn't leave the screen. Maybe I should change the 'self' to something else? – SunnyDay1203 Sep 25 '14 at 17:15
  • I dont play darts :) ... if you "know" that self's bounding box is the full screen, then you are right and i have no further explanation to offer. luck – YvesLeBorg Sep 25 '14 at 17:24
  • 1
    What happens if you touch the screen with two fingers? Are the positions maybe fighting between *any* touch? – CodeSmile Sep 25 '14 at 18:55
  • 2 fingers has no effect :/ It seems like the game stops reading the movement every now and then...I think that's the best way I can describe it. – SunnyDay1203 Sep 25 '14 at 19:11
  • Ok, I'm sure it must be memory. I copied this code onto a simple game with hardly any sprites and it worked perfectly. Gosh darn it. – SunnyDay1203 Sep 25 '14 at 19:32

1 Answers1

0

Ok I've got it!

I had to unEnable the UISwipeGestureRecognizers while I moved the sprite.

The game was registering my touchesMoved movement as a swipe, and cancelling the touchesMoved commands.