0
我將3張圖像(精靈)從屏幕右側移動到屏幕中間。我寫了下面的代碼,但是想知道是否有更高效的代碼編碼方式。CCSprite高效動畫
-(void) displayMenu
{
CGSize screenSize = [[CCDirector sharedDirector] winSizeInPixels];
CCSprite* menuItemBottle = [CCSprite spriteWithFile:@"btn_i_have_norm.png"];
menuItemBottle.position = ccp((screenSize.width * 2), 600.0f);
menuItemBottle.contentSize = screenSize;
menuItemBottle.scale = 1;
[self addChild:menuItemBottle z:0 tag:4];
CCSprite* menuItemAdvert = [CCSprite spriteWithFile:@"btn_see-ad_norm.png"];
menuItemAdvert.position = ccp((screenSize.width * 2), 500.0f);
menuItemAdvert.contentSize = screenSize;
menuItemAdvert.scale = 1;
[self addChild:menuItemAdvert z:0 tag:5];
CCSprite* menuItemNoBottle = [CCSprite spriteWithFile:@"btn_dont-have_norm.png"];
menuItemNoBottle.position = ccp((screenSize.width * 2), 400.0f);
menuItemNoBottle.contentSize = screenSize;
menuItemNoBottle.scale = 1;
[self addChild:menuItemNoBottle z:0 tag:6];
CGPoint newPointBottle = CGPointMake(screenSize.width * 0.5f + 50, 600.0f);
CCMoveTo *moveBottle = [CCMoveTo actionWithDuration:0.7f position:newPointBottle];
CCSequence *sequenceBottle = [CCSequence actions:moveBottle, nil];
[menuItemBottle runAction:sequenceBottle];
CGPoint newPointAdvert = CGPointMake(screenSize.width * 0.5f + 50, 500.0f);
CCMoveTo *moveAdvert = [CCMoveTo actionWithDuration:0.7f position:newPointAdvert];
CCSequence *sequenceAdvert = [CCSequence actions:moveAdvert, nil];
[menuItemAdvert runAction:sequenceAdvert];
CGPoint newPointNoBottle = CGPointMake(screenSize.width * 0.5f + 50, 400.0f);
CCMoveTo *moveNoBottle = [CCMoveTo actionWithDuration:0.7f position:newPointNoBottle];
CCSequence *sequenceNoBottle = [CCSequence actions:moveNoBottle, nil];
[menuItemNoBottle runAction:sequenceNoBottle];
}
效率更低,代碼更快,效率更高? – lins314159
更少的代碼,如果運行更快,那麼太棒了! – daidai