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-23-2012, 02:54 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
arbitur is on a distinguished road
Default mathematics for steering

hi, im making a snake game where u can steer to the left and right with 2 buttons smoothly. the snake's speed is gonna be the same all the time while u are turning left or right.

the problem im having is that i dont know the math for it.
if u know it i'd be very grateful if u could share ur knowledge.

p.s im using cocos2d.
arbitur is offline   Reply With Quote
Old 01-23-2012, 03:16 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by arbitur View Post
hi, im making a snake game where u can steer to the left and right with 2 buttons smoothly. the snake's speed is gonna be the same all the time while u are turning left or right.

the problem im having is that i dont know the math for it.
if u know it i'd be very grateful if u could share ur knowledge.

p.s im using cocos2d.
You're going to have to be more specific. How are you representing motion? Do you have a delta that you apply to the snake for each frame? Are you using compass directions? What is the coordinate system in Cocos2D? (center of the screen is 0,0, with positive movement up and to the right, or is the zero point in the upper left, with increases in x and y going right and down?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-23-2012, 04:02 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
arbitur is on a distinguished road
Default

here is my code so far:

-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {

worm1 = [CCSprite spriteWithFile:@"ball.png"];
worm1.position = ccp(240, 160);

[self addChild:worm1];

CCMenuItem *btn = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png" target:self selector:@selector(steerLeft)];
CCMenuItem *btn2 = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png" target:self selector:@selector(steerRight)];
CCMenu *jumpbtn = [CCMenu menuWithItems:btn, nil];
CCMenu *jumpbtn2 = [CCMenu menuWithItems:btn2, nil];

jumpbtn.position = ccp(20, 20);
jumpbtn2.position = ccp(460, 20);

[self addChild:jumpbtn];
[self addChild:jumpbtn2];

[self schedule:@selector(moveworm1) interval:.1];
}
return self;
}

-(void)moveworm1 {
CCSprite *worm1body = [CCSprite spriteWithFile:@"ball.png"];
worm1body.position = worm1.position;

[self addChild:worm1body];

}

-(void)steerLeft {

}

-(void)steerRight {

}




0,0 is in the bottomleft corner.
arbitur is offline   Reply With Quote
Old 01-23-2012, 04:50 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by arbitur View Post
here is my code so far:

-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {

worm1 = [CCSprite spriteWithFile:@"ball.png"];
worm1.position = ccp(240, 160);

[self addChild:worm1];

CCMenuItem *btn = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png" target:self selector:@selector(steerLeft)];
CCMenuItem *btn2 = [CCMenuItemImage itemFromNormalImage:@"Icon-Small.png" selectedImage:@"Icon.png" target:self selector:@selector(steerRight)];
CCMenu *jumpbtn = [CCMenu menuWithItems:btn, nil];
CCMenu *jumpbtn2 = [CCMenu menuWithItems:btn2, nil];

jumpbtn.position = ccp(20, 20);
jumpbtn2.position = ccp(460, 20);

[self addChild:jumpbtn];
[self addChild:jumpbtn2];

[self schedule:@selector(moveworm1) interval:.1];
}
return self;
}

-(void)moveworm1 {
CCSprite *worm1body = [CCSprite spriteWithFile:@"ball.png"];
worm1body.position = worm1.position;

[self addChild:worm1body];

}

-(void)steerLeft {

}

-(void)steerRight {

}




0,0 is in the bottomleft corner.
Use code tags!

How are you describing the direction of movement? How do you move the snake to a new location if it doesn't steer? I'm not going to write your whole program for you.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
cocos2d, iphone, movement, sprite, xcode

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: 378
11 members and 367 guests
7twenty7, Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
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:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0