Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-25-2012, 08:54 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
arbitur is on a distinguished road
Default 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.
arbitur is offline   Reply With Quote
Reply

Bookmarks

Tags
button pressed, cocos 2d, function, iphone

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 394
11 members and 383 guests
Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0