cocos2diphone中的阻力控制优化

cocos2diphone中的阻力控制优化,iphone,optimization,cocos2d-iphone,Iphone,Optimization,Cocos2d Iphone,我正在写一个简单的侧面滚动iOS游戏,它的控制与《飞仓鼠》中的控制相同,也就是说,你拖动手指将主角移动到屏幕上的任何地方。 现在游戏几乎完成了,但我有一个严重的问题:所有的敌人和背景物体移动平稳,除了主角:( 事实上,游戏的整体画面总是在40fps以上,只是主角移动不平稳,好像低于10fps。 你能看看我下面的代码并告诉我出了什么问题吗? 任何帮助都将不胜感激 这是我的密码 -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEven

我正在写一个简单的侧面滚动iOS游戏,它的控制与《飞仓鼠》中的控制相同,也就是说,你拖动手指将主角移动到屏幕上的任何地方。 现在游戏几乎完成了,但我有一个严重的问题:所有的敌人和背景物体移动平稳,除了主角:(

事实上,游戏的整体画面总是在40fps以上,只是主角移动不平稳,好像低于10fps。 你能看看我下面的代码并告诉我出了什么问题吗? 任何帮助都将不胜感激

这是我的密码

    -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent*)event{

    if (isGameOver == YES || isGamePause == YES) {    
        return;    
    }             
    UITouch *touch = [touches anyObject];    
    CGPoint touchLocation = [touch locationInView: [touch view]]; 
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];    
    CGPoint diff = ccpSub(touchLocation,beforePosTouch);    
    beforePosTouch = touchLocation;      
    CGPoint positionOfPlayer = player.position;    
    CGPoint newPos = ccpAdd(positionOfPlayer, diff);    
    if (newPos.x <playerWidth + leftLimit) {    
        return;    
    } 

    else if (newPos.x > rightLimit - playerWidth)

    {    
        return;    
    }

    if (newPos.y < playerHeight) {    
        return;    
    }    
    else if (newPos.y > screenSize.height - playerHeight)    
    {    
        return;
    }    
    [player setPosition:newPos];          
    }    
}

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    
    UITouch *touch = [touches anyObject];    
    beforePosTouch = [touch locationInView:[touch view]];    
    beforePosTouch = [[CCDirector sharedDirector] convertToGL:beforePosTouch];    
}
-(void)CCTouchsMoved:(NSSet*)触摸事件:(UIEvent*)事件{
如果(isGameOver==YES | | isGamePause==YES){
返回;
}             
UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置视图:[触摸视图]];
touchLocation=[[CCDirector sharedDirector]convertToGL:touchLocation];
CGPoint diff=ccpSub(触摸位置,前后触摸之前);
BeforePostTouch=触摸位置;
CGPoint positionOfPlayer=player.position;
CGPoint newPos=ccpAdd(层的位置,差异);
if(新位置x右侧限制-播放器宽度)
{    
返回;
}
如果(newPos.yscreenSize.height-播放器高度)
{    
返回;
}    
[玩家设置位置:newPos];
}    
}
-(void)CCTouchesStart:(NSSet*)接触事件:(UIEvent*)事件{
UITouch*touch=[触摸任何对象];
BeforePostTouch=[触摸位置视图:[触摸视图]];
beforePosTouch=[[CCDirector sharedDirector]convertToGL:beforePosTouch];
}

此代码不能成为您程序的瓶颈。您必须找到瓶颈。代码中对您的游戏性能非常重要的部分。

同意。其他地方一定有一个对象使您速度变慢。我也这么认为,但我目前不太了解Cocos2D引擎如何处理这些事件,即。e、 它调用这些方法的次数。如果我在屏幕上移动一个像素,那么该代码将被调用一次?如果我在屏幕上滑动,那么将有数百个像素,那么该代码将被调用数百次?任何cocos2D专家请帮助。谢谢,LotusCos2D与任何其他UIView一样处理触摸。实际上,触摸它由openGLView处理,然后传递给cocos2d。这是一个廉价的操作