Hey everyone, I'm new to cocos2d and Objective-C so I apologize if there is a simple solution. I am working on some code for a game I am developing. In this game I have a sprite on screen, and I would like this sprite to move opposite of the touch location.
Example: Picture Example
So far my code looks like this:
-(void) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
//Determine location of the tap/touch
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
I add my sprite to the scene in the init method like so:
CGSize screenSize = [[CCDirector sharedDirector] winSize];
Ball* ball = [Ball ball];
ball.position = CGPointMake(ball.contentSize.width / 2, screenSize.height / 2);
[self addChild:ball z:2];
I would like it so that wherever I touch on the screen, the sprite will move 20pixels opposite of that touch location. So if I touch to the left of the sprite, the sprite moves right, if I touch to the top, the sprite will move down..etc.
Thanks for the help!