0
我有一個Enemy類在一個給定位置的GameplayLayer上創建。當我產生敵人,然後返回它在日誌中的當前位置時,它返回它在(正確)創建的位置。現在,我正試圖給敵人類的更新方法添加一些動作。然而,當我這樣做時,它會「傳送」敵人到0,0位置,然後將運動應用到它。當我從其更新方法中返回敵人的位置時,它會報告0,0,而不是它產生的位置。Cocos2d - 對象似乎正在重置其位置
現在,我正在使用動畫來表示屏幕上的敵人。我可以像使用精靈一樣訪問動畫的位置,還是完全錯過了某些內容?
在遊戲層產卵敵人:
CCLOG(@"Creating Enemy");
Enemy *enemy = [[Enemy alloc] initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"node-red-1.png"]];
[enemy setPosition:spawnLocation];
[sceneSpriteBatchNode addChild:enemy z:ZValue tag:kEnemySpriteTagValue];
[enemies addObject:enemy];
敵人移動的動作:
CCLOG(@"Enemy->Starting the Traveling Animation");
action = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:skullRedAnim restoreOriginalFrame:NO]];
self.moveAction = [CCMoveBy actionWithDuration:(screenSize.height/200) position:ccp(self.position.x, screenSize.height + 100)];
[self runAction:moveAction];
break;