私の新しいゲームでは、2 人のプレイヤーを同時に動かすために、cocos2d でマルチタッチを処理する必要があります。ただし、タッチが遅いように見えることがあります。私がプレイしているときはすべてがとてもスムーズですが、プレイヤーの動きに合わせてラグが発生しますが、他のオブジェクトはスムーズに動きます! そこで、プロファイリングを実行することにしました。すべて問題なく、「ラグ」があっても、ゲームは常に 56 ~ 60 fps で実行されていました。したがって、メモリやFPSの問題ではなく、タッチ処理の問題だと思います...これが私のコードです:
- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
tapCount ++;
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//Do my stuff here...
NSLog(@"Tap Count:%d", tapCount);
}
}
- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (tapCount == 0) return;
for (UITouch *touch in touches) {
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CGPoint prevLocation = [[CCDirector sharedDirector] convertToGL:[touch previousLocationInView:[touch view]]];
float diff = (location.y - prevLocation.y) / ipadScale * SENSIVITY;
//MOVE MY PLAYERS HERE
}
}
- (void) ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self ccTouchesEnded:touches withEvent:event];
}
- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
tapCount--;
NSLog(@"Tap Count:%d", tapCount);
}
if (tapCount <= 0) {
tapCount = 0;
[self pauseGame];
}
}
自分のゲーム シーンも Standard Delegate として登録していますが、問題はありますか? マルチタッチに必要だからじゃないのかな!このコードにも問題はないと思いますが、そうですか? ラグがあると言うと、25 FPS で実行しているようなもので、大したことではありませんが、ちょっと面倒です!
私を助けてください!ありがとうございました!