V.V
V.V

Reputation: 3094

move sprite by using touchmoved in specified regions of screen

I am making an application, in that I want to move the sprite in a specified region of the screen, With cocos2d I am not able to make move of sprite, I only know the method -(void)ccTouchMoved:(UITouch *)touches withEvent:(UIEvent *)event, but I don't know how to move a sprite,

can any one help me????

Thanks in advance

Upvotes: 0

Views: 744

Answers (1)

Alex Winston
Alex Winston

Reputation: 651

Try something like the following.

-(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch * touch = [touches anyObject];
    CGPoint location = [[Director sharedDirector] convertCoordinate:
                        [touch locationInView:touch.view]];    
    [yourSprite setPosition:ccp(location.x , location.y )];
    return kEventHandled;
}

Edit: If you simply want to move the sprite without a touch event simply call

[yourSprite setPosition:ccp(someX, someY)];

Upvotes: 2

Related Questions