Ios 沿滑动方向移动精灵
我想将我的精灵(宇宙飞船)向用户的滑动方向移动。 即, 向左移动-向左滑动 向上移动-向上滑动等 我不熟悉刷卡编码,因此请提供帮助。这可以:Ios 沿滑动方向移动精灵,ios,cocos2d-iphone,swipe,Ios,Cocos2d Iphone,Swipe,我想将我的精灵(宇宙飞船)向用户的滑动方向移动。 即, 向左移动-向左滑动 向上移动-向上滑动等 我不熟悉刷卡编码,因此请提供帮助。这可以: - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if (touchState != kSceneStateUngrabbed) return NO; // Store the starting touch point CGPoint tou
- (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;
}
-(BOOL)cctouch开始:(UITouch*)触摸事件:(UIEvent*)事件
{
如果(touchtate!=kscenstatengrabbed)返回否;
//存储起始接触点
CGPoint touchPoint=[touch location inview:[touch view]];
startTouchPoint=接触点;
接触点=[[CCDirector sharedDirector]convertToGL:接触点];
//改变触摸状态
touchState=kscenstategrabbed;
返回YES;
}
-(无效)ccTouchMoved:(UITouch*)触摸事件:(UIEvent*)事件
{
CGPoint touchPoint=[touch location inview:[touch view]];
float RIGHT LEFT=接触点.x-开始接触点.x;
浮动上下=接触点.y-开始接触点.y;
如果(防抱死制动系统(左右)>防抱死制动系统(上下)){
如果(右左>0)
{
[spaceShip runAction:[CCMoveTo Action WithDuration:1位置:ccp(winsize.width,spaceShip.position.y)];
}
其他的
[spaceShip runAction:[CCMoveTo Action with Duration:1位置:ccp(0,spaceShip.position.y)];
}
否则{
如果(向上向下)什么是触摸状态,kscenstatengrabbed?假设startTouchPoint是CGPoint。