cocos2d calling button method while its pressed down
ok so im making a game where i have 2 buttns 1 that steer to the left and 1 to the right.
my coding for it:
#import "HelloWorldLayer.h"
CCSprite *player;
float maxspeed = 3;
float rotatestep = 4;
int leftOrRight;
CCMenuItem *btnL;
CCMenuItem *btnR;
// HelloWorldLayer implementation
@implementation HelloWorldLayer
+(CCScene *) scene {}
-(id) init
{ if( (self=[super init])) {
player = [CCSprite spriteWithFile:@"Icon-Small.png"];
player.position = ccp(240, 160);
[self addChild:player];
CCMenuItem *btnL = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png"];
CCMenuItem *btnR = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png"];
btnL.position = ccp(30,30);
btnR.position = ccp(450,30);
[self addChild:btnL];
[self addChild:btnR];
[self schedule:@selector(steer) interval:.02];
}
return self;
}
-(void)steer {
float speed = maxspeed;
if (btnR.isSelected == YES) {
player.rotation += rotatestep*(speed/maxspeed);
}
if (btnL.isSelected == YES) {
player.rotation -= rotatestep*(speed/maxspeed);
}
}
- (void) dealloc{}
@end
no the problem with this is when i press the buttons they wont be pressed down and does nothing.
please help me with this problem.
|