0

ユーザーからのスワイプの方向にスプライト(宇宙船)を移動したい。つまり、左に移動 - 左にスワイプ 上に移動 - 上にスワイプ など。

スワイプコーディングは初めてなので、助けてください。

4

1 に答える 1

1

これでできます:

 - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{


    if (touchState != kSceneStateUngrabbed) return NO;

    // Store the starting touch point
    CGPoint touchPoint = [touch locationInView:[touch view]];
    startTouchPoint = touchPoint;

    touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];




    // Change touch state
    touchState = kSceneStateGrabbed;

    return YES;
}



    - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
    {
        CGPoint touchPoint = [touch locationInView:[touch view]];




        float rightleft = touchPoint.x-startTouchPoint.x ;
        float updown =  touchPoint.y-startTouchPoint.y;
        if(abs(rightleft)>abs(updown)){
            if(rightleft>0)
            {
                [ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(winsize.width,     spaceShip.position.y)]];

                }
                else
                [ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(0, spaceShip.position.y)]];
            }
        else{
                if(updown<0){
                [ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(spaceShip.position.x, winsize.height)]];
                        }
                else
                [ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(spaceShip.position.x, 0)]];

            }

    }

    - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
    {
        // Change touch state
        touchState = kSceneStateUngrabbed;


    }
于 2013-01-10T10:52:57.253 に答える