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 08-19-2011, 02:26 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 11
bharat is on a distinguished road
Default moving ball

hi everyone..i am new to iphone development..
can any one plz tell me how to start and stop a ball with start and stop button respectively...
bharat is offline   Reply With Quote
Old 08-19-2011, 02:37 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 11
bharat is on a distinguished road
Default

can anyone plzz help..
bharat is offline   Reply With Quote
Old 08-19-2011, 03:17 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Sweden
Posts: 28
Slade is on a distinguished road
Default

Are you starting from scratch? Is the ball you want to move displayed on your screen? If so please show us some of your code, it will be easier to help you then :-)
Slade is offline   Reply With Quote
Old 08-19-2011, 06:17 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 11
bharat is on a distinguished road
Default

yes starting from fresh...i want to move a ball by pressing the button...


-(void) onTimer{
ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos. y);
if(ball.center.x > 320 || ball.center.x < 0)
pos.x = -pos.x;
if(ball.center.y > 460 || ball.center.y < 0)
pos.y = -pos.y;

}

- (void)viewDidLoad
{
pos=CGPointMake(14.0, 7.0);

}
now i want that when the stimulator opens the ball remains still and after pressing the start button it should move and then stop after pressing stop..
may be i have to do something inside
- (IBAction)buttonPressedid)sender..
no idea..
bharat is offline   Reply With Quote
Old 08-19-2011, 07:23 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Quote:
Originally Posted by bharat View Post
yes starting from fresh...i want to move a ball by pressing the button...


-(void) onTimer{
ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos. y);
if(ball.center.x > 320 || ball.center.x < 0)
pos.x = -pos.x;
if(ball.center.y > 460 || ball.center.y < 0)
pos.y = -pos.y;*/

}

- (void)viewDidLoad
{
pos=CGPointMake(14.0, 7.0);

}
now i want that when the stimulator opens the ball remains still and after pressing the start button it should move and then stop after pressing stop..
may be i have to do something inside
- (IBAction)buttonPressedid)sender..
no idea..
Change your time code to - a variable from the pos.x and change the value of the variable on your buttonPressed method:

Code:
int moveX = 0;
int moveY = 0;

-(void) onTimer{
    ball.center = CGPointMake(ball.center.x+moveX,ball.center.y+moveY);  
/*
    if(ball.center.x > 320 || ball.center.x < 0)
        pos.x = -pos.x;
    if(ball.center.y > 460 || ball.center.y < 0)
        pos.y = -pos.y;
*/
    
}

/*
- (void)viewDidLoad
{
    pos=CGPointMake(14.0, 7.0);
    
}*/

- (IBAction)buttonPressed:(id)sender {
    if (moveX > 0) {
        moveX = 0;
    } else {
        moveX = 1;
    }
}
__________________
Justinmichael is offline   Reply With Quote
Old 08-19-2011, 07:33 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Sweden
Posts: 28
Slade is on a distinguished road
Default

DonŽt worry, IŽm sure weŽll be able to make the ball move :-). If you want the ball to start and stop after pushing the buttons I would introduce a new variable: speed. When you press the stop button the speed should be set to zero. And the start button should set the speed to 1. But then you need to change your code a little. For example:

if(ball.center.x < 320 || ball.center.x > 0)
ball.center.x = ball.center.x + speed;
if(ball.center.y < 480 || ball.center.y > 0)
ball.center.y = ball.center.y + speed;

I corrected the code a litte, it should check that the ball is inside the screens boundaries :-). Also, you should change the direction of the ball once it hits the walls but we can save that for later. Try it out and see it you can get the ball moving.
Slade is offline   Reply With Quote
Old 08-19-2011, 11:11 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 11
bharat is on a distinguished road
Default

Quote:
Originally Posted by Justinmichael View Post
Change your time code to - a variable from the pos.x and change the value of the variable on your buttonPressed method:

Code:
int moveX = 0;
int moveY = 0;

-(void) onTimer{
    ball.center = CGPointMake(ball.center.x+moveX,ball.center.y+moveY);  
/*
    if(ball.center.x > 320 || ball.center.x < 0)
        pos.x = -pos.x;
    if(ball.center.y > 460 || ball.center.y < 0)
        pos.y = -pos.y;
*/
    
}

/*
- (void)viewDidLoad
{
    pos=CGPointMake(14.0, 7.0);
    
}*/

- (IBAction)buttonPressed:(id)sender {
    if (moveX > 0) {
        moveX = 0;
    } else {
        moveX = 1;
    }
}


hey thnks a lot for your help....bt still nt able to do...
when the build runs the ball is still but when i press the start or stop button its not moving...how to move ie..how to link the ball movement with those two button?????
bharat is offline   Reply With Quote
Old 08-19-2011, 11:39 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 11
bharat is on a distinguished road
Default

Quote:
Originally Posted by Slade View Post
DonŽt worry, IŽm sure weŽll be able to make the ball move :-). If you want the ball to start and stop after pushing the buttons I would introduce a new variable: speed. When you press the stop button the speed should be set to zero. And the start button should set the speed to 1. But then you need to change your code a little. For example:

if(ball.center.x < 320 || ball.center.x > 0)
ball.center.x = ball.center.x + speed;
if(ball.center.y < 480 || ball.center.y > 0)
ball.center.y = ball.center.y + speed;

I corrected the code a litte, it should check that the ball is inside the screens boundaries :-). Also, you should change the direction of the ball once it hits the walls but we can save that for later. Try it out and see it you can get the ball moving.

thnx for your help..bt am not able to get it done...
bharat is offline   Reply With Quote
Old 08-20-2011, 11:45 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Sydney, Australia
Posts: 44
new2objectivec is on a distinguished road
Default

try this: Making a simple iPhone game, part 1 - YouTube

ball bouncing game tutorial with full video
new2objectivec 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: 399
13 members and 386 guests
7twenty7, AppsBlogger, comicool, Creativ, Dalia, dansparrow, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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