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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-20-2010, 07:08 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 25
rensu is on a distinguished road
Default Joystick and Jump problem

Hey guys

I need some advice

I have a very basic game in development and I am at the stage where I need to create a UI Joystick to control the main character. My idea is to have a circle for where your thumb will be placed. Around the circle is a small ball which goes around the circumference of the circle. This is to set the angle at which the play will jump. Can some one give me some advice as where to start and what to look into to achieve this .

My second problem is im not too sure how to add gravity to my game .

At the moment i have a collision detection which checks to see if the player is on a platform and if hes not then he continues to fall at a constant rate. WHen the player touches the screen the player needs to jump but at the moment he just teleports 20 pixels up into the air. How can I make it so the players sprite jumps realistically.

im not looking for code more advice and what to research into but any code would be greatly appreciated.
rensu is offline   Reply With Quote
Old 02-20-2010, 08:42 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by rensu View Post
Hey guys

I need some advice

I have a very basic game in development and I am at the stage where I need to create a UI Joystick to control the main character. My idea is to have a circle for where your thumb will be placed. Around the circle is a small ball which goes around the circumference of the circle. This is to set the angle at which the play will jump. Can some one give me some advice as where to start and what to look into to achieve this .

My second problem is im not too sure how to add gravity to my game .

At the moment i have a collision detection which checks to see if the player is on a platform and if hes not then he continues to fall at a constant rate. WHen the player touches the screen the player needs to jump but at the moment he just teleports 20 pixels up into the air. How can I make it so the players sprite jumps realistically.

im not looking for code more advice and what to research into but any code would be greatly appreciated.
I advice you to use Cocos2d, and for collision\gravity use Chipmunk (or Box2d) that are physics engine
cocos2d for iPhone

I started using it recently and it is awesome, a great framework for 2d game developing on iphone

it include also a template to start using Chipmunk and Box2d. More info on cocos2d's forum and Chipmunk\Box2d 's forum. You can see Documentation and Forum as sources, if you want to support the author and speed up the learning process consider to buy Sapus Tongue Source Code (written by cocos2d's founder), you can see more info in cocos2d's site.

For Joystick you can use it
[joystick] SneakyJoystick 0.1! cocos2d for iPhone
I think that i will replace my own Joystick class with it, it is complete and flexible

Basically for a jump you will apply a force perpendicular to X axis, but it is not usefull that i post code, because you need to start reading about cocos2d and then about chipmunk (Scene, CCLayer, schedule, CCsprite , cpBody, cpShape and other arguments.)

Good Luck!
__________________

Last edited by dany_dev; 02-20-2010 at 08:54 AM.
dany_dev is offline   Reply With Quote
Old 02-20-2010, 11:55 AM   #3 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

For your virtual joystick, consider what you've got to work with:
  • The "joystick" has a (usually fixed) position on screen. Specifically, there is a joystick center at some (Jx, Jy) on the screen
  • The user will have her finger/thumb somewhere around the joystick center, at (Tx, Ty), indicating the direction she wishes to move.
  • You know the value of (Jx, Jy), and track (Tx, Ty) because you're a good programmer and you know how to listen for touch events in your game.
  • You can calculate the vector from the joystick center to the thumb location with a simple calculation Dx = Tx- Jx, Dy = Ty - Jy.
  • Once you have (Dx, Dy), obtaining an angle is trivial, using the arctangent function atan2().
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 02-20-2010, 12:02 PM   #4 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

Quote:
Originally Posted by rensu View Post
My second problem is im not too sure how to add gravity to my game .

At the moment i have a collision detection which checks to see if the player is on a platform and if hes not then he continues to fall at a constant rate. WHen the player touches the screen the player needs to jump but at the moment he just teleports 20 pixels up into the air. How can I make it so the players sprite jumps realistically.
Rather than falling at a constant rate, store the fall rate in a variable, let's call it velocityY. Every frame rather than adding your constant value, add velocityY. Then reset velocityY to zero if there's a collision and otherwise take a fixed value to represent gravity off it each frame.

Gravity in the real world produces acceleration rather than a constant movement so this will lend a more realistic effect. It also neatly solves your jump problem, because you can simply set velocityY to a suitable positive value when you press jump and the gravity modification on each frame will produce the correct parabolic jump.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Reply

Bookmarks

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: 401
8 members and 393 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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