[cocos2d]using CCSprite from HelloWorldLayer in other classes
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 calle开发者_如何学God (after)");
so basically I wrote this code and NSLogs are working fine but my player sprite is not moving... i don't think the code (CCMoveBy) is wrong. so First I thought its not calling HelloWorldLayer so I tried this.
I put this code in my other class.
HelloWorldLayer *helloWorldLayer = [HelloWorldLayer node];
//calling HelloWorldLayer
[helloWorldLayer moveMyCharacter];
and this code in my HelloWorldLayer
-(void)moveMyCharacter
NSLog(@"MOVE UP");
id moveup = [CCMoveBy actionWithDuration:0.1 position:ccp(0, 5)];
[_player runAction:moveup];
and the NSLog worked, but the character is not moving...
I need some help :(
Where are you calling this? By calling [HelloWorldLayer node]
, you are creating a new layer every time this code is run. Unless you add this new layer to a scene, you won't see anything change. You probably want to get a reference to the layer you already have instead of creating a new one.
精彩评论