开发者

move sprite by using touchmoved in specified regions of screen

开发者 https://www.devze.com 2022-12-30 23:05 出处:网络
I am making an application, in tha开发者_如何转开发t 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)ccTo

I am making an application, in tha开发者_如何转开发t 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


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)];
0

精彩评论

暂无评论...
验证码 换一张
取 消