tri*_*ta2 1 iphone cocos2d-iphone
我用Cocos2D写了一个简单的游戏,我有一个动画精灵在纯绿色的田野里走来走去.
步行精灵是64x64px,操纵杆来自Sneakyjoystick类,绿色区域由5-6个32x32像素组成,使用Tiled制作成tilemap.使用Tiled,我创建了一个50 x 50的瓷砖地图.
我得到20-30 FPS,我不知道为什么.我将瓷砖地图尺寸减小到10x10瓷砖,最高可达50-60 FPS.我不知道该怎么办?
编辑:我已经为游戏玩法层添加了初始化块.我在模拟器上测试.
-(id) init
{
if( (self=[super init] ))
{
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"TileMap.tmx"];
self.background = [_tileMap layerNamed:@"Background"];
self.meta = [_tileMap layerNamed:@"Meta"];
self.topLayer = [_tileMap layerNamed:@"TopLayer"];
_topLayer.visible = YES;
_background.visible = YES;
_meta.visible = YES;
[self addChild:_tileMap z:-1];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@"male_walkcycle.plist"];
sceneSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"male_walkcycle.png"];
[self addChild:sceneSpriteBatchNode z:0];
CCTMXObjectGroup *objects = [_tileMap objectGroupNamed:@"Objects"];
NSAssert(objects != nil, @"'Objects' object group not found");
NSMutableDictionary *spawnPoint = [objects objectNamed:@"SpawnPoint"];
NSAssert(spawnPoint != nil, @"SpawnPoint object not found");
int x = [[spawnPoint valueForKey:@"x"] intValue];
int y = [[spawnPoint valueForKey:@"y"] intValue];
Caster *casterPlayer = [[[Caster alloc] init] initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"male_walkcycle_19.png"]];
casterPlayer.position = ccp(x, y);
casterPlayer.joystick = nil;
[sceneSpriteBatchNode addChild:casterPlayer z:1000 tag:kCasterTagValue];
[casterPlayer release];
CCSprite *sprite = [CCSprite node];
CGSize size = CGSizeMake(50,50);
GLubyte *buffer = malloc(sizeof(GLubyte)*4);
for (int i=0;i<4;i++) {buffer[i]=255;}
CCTexture2D *tex = [[CCTexture2D alloc] initWithData:buffer pixelFormat:kCCTexture2DPixelFormat_RGB5A1 pixelsWide:1 pixelsHigh:1 contentSize:size];
[sprite setTexture:tex];
[sprite setTextureRect:CGRectMake(0, 0, size.width, size.height)];
free(buffer);
sprite.position = ccp(x, y);
sprite.visible = NO;
[self addChild:sprite z:5 tag:debugBoxTagValue];
[self setViewpointCenter:casterPlayer.position];
[self scheduleUpdate];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我在模拟器上测试.
我无法相信我需要多久重复一次:
忽略模拟器!
模拟器不是真正的iOS设备.它在你的Mac上运行.它有更多的内存和CPU功率.同时它的渲染性能受到严格限制,因为它不是硬件加速渲染,而是一个软件渲染器.
即便是最快的2012 iMac也无法在iPad或iPhone Retina模拟器上以60 fps运行场景.在iPad Retina模拟器上,你很幸运能获得20 fps.
此外,开发人员是唯一一个在模拟器上运行他们的应用程序的人.您的用户,甚至是您的测试人员,都将使用模拟器来运行您的应用.他们将使用实际的设备.
任何时候在模拟器上优化性能都只是浪费时间.这通常适用于仅在模拟器上发生的任何问题.
在设备上测试!仅在iOS模拟器上观察到的每个问题都没有实际意义,无效,无效,完全不相关,尤其是性能.
| 归档时间: |
|
| 查看次数: |
1353 次 |
| 最近记录: |