2011-08-12 35 views
0
NSLog(@"lets test if this is called (before)"); 

HelloWorldLayer *helloWorldLayer = [HelloWorldLayer node]; 
//calling HelloWorldLayer 

id moveup = [CCMoveBy actionWithDuration:0.1 position:ccp(0, 5)]; 
[helloWorldLayer.player runAction:moveup]; 

NSLog(@"lets test if this is called (after)"); 

所以基本上我寫了這個代碼和NSLogs都工作正常,但我的球員精靈不動...我不認爲代碼(CCMoveBy)是錯誤的。所以首先我認爲它沒有調用HelloWorldLayer,所以我嘗試了這個。[cocos2d中]利用HelloWorldLayer CCSprite其他類

我把這段代碼放到了我的其他類中。

HelloWorldLayer *helloWorldLayer = [HelloWorldLayer node]; 
//calling HelloWorldLayer 

[helloWorldLayer moveMyCharacter]; 

這個代碼我HelloWorldLayer

-(void)moveMyCharacter 
    NSLog(@"MOVE UP"); 

id moveup = [CCMoveBy actionWithDuration:0.1 position:ccp(0, 5)]; 
[_player runAction:moveup]; 

和NSLog的工作,但性格不動......

我需要一些幫助:(

+0

你似乎在1/6秒內將你的角色移動5個像素。你會注意到這麼小的快速移動嗎?嘗試移動它更慢更遠。 – willc2

回答

0

在哪裏你調用了這個函數嗎?通過調用[HelloWorldLayer node],你每次運行代碼時都會創建一個新層,除非你將這個新層添加到場景中,否則你不會看到任何改變。我想要獲得對已有圖層的引用,而不是創建新圖層。

+0

哦,所以我應該將其更改爲包含我的播放器精靈的特定圖層? – user865881