0
votes

I have a problem dragging a sprite i've got the sprite moving left and right while keeping the y position the same, but i can't get the sprite to move up or down when the x position stays the same. Also in the cctouchended the sprite moves so that it is in a fixed position, when all touches have ended I am trying to make a game like slidieo/skozzle. Could do with some help

c1 is the column that is being moved, r1 is the row that is being moved, [pos objectAtIndex:0] is the sprite's:red1 position and checks if the sprite is in c1 as every time you go into the game the sprite has a new random position and t1 is the cgrect of the sprite so that you must be clicking on the spirte because if you don't when you click above the sprite and try moving the sprite jumps to the touchlocation.

here is my code:

CGPoint touchLocation = [touch locationInView:[touch view]];
CGPoint prevLocation = [touch previousLocationInView:[touch view]];

touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
prevLocation = [[CCDirector sharedDirector] convertToGL:prevLocation];

   if (CGRectContainsPoint(c1,touchLocation)) {
            if (CGRectContainsPoint(c1,[[pos objectAtIndex:0]CGPointValue])) {
        if (CGRectContainsPoint(t1,touchLocation)) {
            if (touchLocation.y>0||touchLocation.y<0) {
                touchLocation.x = red1.position.x;
                [red1 setPosition:ccp(touchLocation.x,touchLocation.y)];
            }
        }
    }
}

            if (touchLocation.x>0||touchLocation.x<0) {
                touchLocation.y=red1.position.y;
                [red1 setPosition:ccp(touchLocation.x,touchLocation.y)];
            }
        }

thanks

1
please provide examples of your code. it's pretty hard to debug from what you've provided. - Bongeh
i've got it kind of working but it is not a smooth transition - Dangermouse

1 Answers

0
votes

i've solved the problem :) just had to remove a few if statements and edit a few, now i've got it moving up and down and when the sprite stops it can move left and right