3D ゲームでは、最適化後、iPad2 で 60fps を達成しました。メイン ランループはセカンダリ スレッドにあり、インターフェイス ビルダーはメイン スレッドに UI を構築します (この質問はメイン スレッドの UI に関するものです)。
2 つのコントローラー、スロットル アップ、およびタッチ インタラクションを使用する UI のロール用スティックがあります。下の画像でスティックを確認できます。
この画像から想像できるように、180度の回転運動があります
ゲームを実行し、このスティックを親指で前後にスクラブすると (0 度から -180 度まで激しく回転)、fps が 60 fps ではなく 33 fps に低下します。
以下のコード リストからこの行をコメント アウトするだけで、fps が 60 fps に戻ります (親指でスクラブすると、ゲームは回転しますが、このスティックの画像はもちろん動きません)。このスティックの画像を更新せずにフル fps でゲームを実行すると (このルーチンだけであることを示しています)、この方法で画像を更新および変換すると、私の fps に大きな影響を与えます。以下のこのコードを参照してください。このパフォーマンス ヒットを回避する方法があると思いますか? (そうでなければ、インフィニティ ブレードだと思うようなゲームで見られるロールのアイデアを与えるために、タッチ領域を表す円だけを含む一般的な丸い領域が必要になります..しかし、私はむしろこのインタラクティブな画像が欲しい本当の目的を示しています。私が見逃しているものはありますか?変更する必要がありますか?より良いでしょうか?
joypadCap.transform = CGAffineTransformMakeRotation(touchAngle); //rotation in radians
これは、設定されたviewControllerの関連コードです。「ジョイパッド」は上の画像です。スロットルは別の画像で、fpsに影響を与えていますが、スロットルがこのCGAffineTransformMakeRotationを使用せずに、画像を正しい場所に移動するだけです。ただし、その操作により fps が約 8fps 低下します。
@interface stickController : UIViewController
{
IBOutlet UIImageView *throttleStickCap;
IBOutlet UIImageView *joypadCap;
etc......
@implementation stickController
@synthesize frontViewButton, backViewButton, leftViewButton, rightViewButton, upViewButton, gunSight;
//------------------------------------------------------------------------------------
- (void)viewDidLoad
{
NSLog(@"viewDidLoad");
[super viewDidLoad];
throttleStick = throttleStickCap.frame;
throttleStickCenterx = throttleStickCap.center.x;
throttleStickCentery = throttleStickCap.center.y;
throttleStickMax = 72.0f;
throttleStickMin = -7.0f;
joypad = joypadCap.frame;
joypadCenterx = joypadCap.center.x;
joypadCentery = joypadCap.center.y;
joypadMax = 50.0f;
joypadMin = -50.0f;
theStickController = self;
}
//------------------------------------------------------------------------------------
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(throttleStick, touchLocation))
{
throttleStickTouchHash = [touch hash];
}
if (CGRectContainsPoint(joypad, touchLocation))
{
joypadTouchHash = [touch hash];
CGPoint touchLocation = [touch locationInView:self.view];
float dx = touchLocation.x - (float)joypadCenterx;
float dy = touchLocation.y - (float)joypadCentery;
distance = sqrtf(powf(dx, 2.0f) + powf(dy, 2.0f));
if (distance > joypadMax)
{
enoughDistance = shootDistance;
createBulletSet();
}
}
}
}
//------------------------------------------------------------------------------------
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
if ([touch hash] == throttleStickTouchHash)
{
CGPoint touchLocation = [touch locationInView:self.view];
distance = throttleStickCentery - touchLocation.y;
if (distance > throttleStickMax)
{
throttleStickCap.center = CGPointMake(throttleStickCenterx, throttleStickCentery - throttleStickMax);
throttle = throttleStickMax;
}
else if (distance < throttleStickMin)
{
throttleStickCap.center = CGPointMake(throttleStickCenterx, throttleStickCentery - throttleStickMin);
throttle = throttleStickMin;
}
else
{
throttleStickCap.center = CGPointMake(throttleStickCap.center.x, touchLocation.y);
throttle = distance;
}
throttle *= .10;
throttleStick = throttleStickCap.frame;
}
if ([touch hash] == joypadTouchHash)
{
CGPoint touchLocation = [touch locationInView:self.view];
float dx = touchLocation.x - (float)joypadCenterx;
float dy = touchLocation.y - (float)joypadCentery;
distance = sqrtf(powf(dx, 2.0f) + powf(dy, 2.0f));
if (distance > joypadMax) createBulletSet();
else enoughDistance = shootDistance;
if (dx > joypadMax) roll = joypadMax;
else if (dx < joypadMin) roll = joypadMin;
else roll = dx;
joypad = joypadCap.frame;
touchAngle = atan2(dy, dx) + 1.570796;
if ((dx < 0.0f) && (dy > 0.0f)) touchAngle = -1.570796;
else if ((dx > 0.0f) && (dy > 0.0f)) touchAngle = 1.570796;
// joypadCap.transform = CGAffineTransformMakeRotation(touchAngle); //rotation in radians
}
}
}
//------------------------------------------------------------------------------------
- (void)forceTouchesEnd
{
throttleStickMoving = NO;
throttleStickTouchHash = 0;
throttle = 0.0f;
throttleStickCap.center = CGPointMake(throttleStickCenterx, throttleStickCentery);
throttleStick = throttleStickCap.frame;
joypadMoving = NO;
joypadTouchHash = 0;
roll = 0.0f;
joypadCap.transform = CGAffineTransformMakeRotation(0.0f); //rotation in radians
joypad = joypadCap.frame;
}
//------------------------------------------------------------------------------------
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
for (UITouch *touch in touches)
{
if ([touch hash] == throttleStickTouchHash)
{
throttleStickTouchHash = 0;
}
if ([touch hash] == joypadTouchHash)
{
joypadTouchHash = 0;
roll = 0.0f;
joypad = joypadCap.frame;
return;
}
}
}