通过在屏幕的指定区域中使用 touchmoved 来移动精灵

发布于 2024-09-02 05:53:46 字数 171 浏览 3 评论 0原文

我正在制作一个应用程序,因为我想在屏幕的指定区域移动精灵,使用cocos2d我无法移动精灵,我只知道方法 -(void)ccTouchMoved:(UITouch *)touches withEvent:(UIEvent *)event,但我不知道如何移动精灵,

有人可以帮助我吗???

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-09-09 05:53:46

尝试如下操作。

-(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;
}

编辑:如果您只是想在没有触摸事件的情况下移动精灵,只需调用

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

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)];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文