@interface GameplayLayer : CCLayer <GameplayLayerDelegate> {
CCSprite *vikingSprite;
SneakyJoystick *leftJoystick;
SneakyButton *jumpButton;
SneakyButton *attackButton;
CCSpriteBatchNode *sceneSpriteBatchNode;
}
@end
#pragma mark –
#pragma mark Update Method
-(void) update:(ccTime)deltaTime {
CCArray *listOfGameObjects =
[sceneSpriteBatchNode children]; // 1
for (GameCharacter *tempChar in listOfGameObjects) { // 2
[tempChar updateStateWithDeltaTime:deltaTime andListOfGameObjects:
listOfGameObjects]; // 3
}
}需要更新的game object放到一个batchNode中,每帧通过children取出。而不需要持有每个对象。
[self scheduleUpdate];
Sets up a scheduler call that will f ire the update method in GameplayLayer.m on every frame.
本文探讨了在游戏开发中如何高效地管理多个游戏对象,通过将需要更新的对象放入一个批节点,每帧通过children方法获取,从而避免了持有每个对象的复杂性,实现了高效的批量更新机制。
2818

被折叠的 条评论
为什么被折叠?



