【问题标题】:move sprite by using touchmoved in specified regions of screen在屏幕的指定区域使用 touchmoved 移动精灵
【发布时间】:2010-05-21 13:10:42
【问题描述】:

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

谁能帮帮我???

提前致谢

【问题讨论】:

    标签: iphone xcode cocos2d-iphone sprite


    【解决方案1】:

    试试下面的方法。

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

    【讨论】:

    • 感谢哥们的支持,我也做了同样的事情,我已经实现了,它正在工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2022-12-11
    • 2015-05-17
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    相关资源
    最近更新 更多