views:

118

answers:

1

hi friends,

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

+1  A: 

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)];
Alex Winston
Thanks buddy for the support, I've done the same and I've implemented it, it's working.
iPhone Fun