ball back on paddle

Talk about making games.

ball back on paddle

Postby Nykos » Wed Jan 12, 2011 9:44 am

Hi everyone, I need some help (again).
My game is almost finished, all I need is one more script information.
I'm making a breakout style game and when my ball gets out of vision, I made it come back on the paddle with this script:

x = paddleleft.x;
y = 27;
xvelocity=0;
yvelocity=0;

Everything works just fine, but what I'd like is that the ball fololows the paddle when it's brought back on it and till mouse button is pressed.

I've searched the forum, watched every demos I could find relative to the subject but i didn't find anything like this.

Anyone has an idea?
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: ball back on paddle

Postby skydereign » Wed Jan 12, 2011 10:07 am

You wouldn't really find the answer by searching this case specifically, though I do remember answering this before. Searching for what you are trying to do, have the ball follow the paddle, would probably work better.

You can either change the ball's parent to the paddle after setting the xy values, or use a variable to determine if the ball should move with the paddle. If you don't already have a variable like that, I'd suggest using the parent method. Just make sure to change the parent back to none when you launch the ball.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: ball back on paddle

Postby Nykos » Thu Jan 13, 2011 7:46 am

Yeah I know you answered this before, but I don't understand the ball state thing you talked about then.
I tried to use parent but the ball acts weirdly, it's not brought back on the paddle but at it's left and beside of it.
My paddle is made of four pieces , three of them are child of the first one, maybe that's the problem.
Even when I change the parent to another paddle piece, the ball re-appears elsewhere.

In fact, at the beggining of the game, the ball is child of the paddle, and when it's launched, it's parent is changed to none.
But it doesn't want to be changed back.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: ball back on paddle

Postby skydereign » Thu Jan 13, 2011 7:58 am

You might get positioning problems if you change the parent before repositioning the ball. If you do, then you should use these values.
Code: Select all
x=0;
y=--height/2-parent.height/2;
// this should position the ball right above the paddle


When something is parented to another actor it's (0,0) becomes the parent's xy coordinates. So if you change the parent before setting the xy, you'd have to set the xy values according to that, instead of the normal absolute coordinates.

For the state, it was just a variable telling the actor that it should be following the paddle. state would have two possible values, 0 which means follow the paddle, and 1 which means normal play. When you want it to follow the paddle, set state equal to zero, and when you launch it set it to one. That way in the ball's draw script, you can use this.
Code: Select all
switch(state)
{
    case 0: // follow paddle
    x=paddle.x;
    y=paddle.y-paddle.height/2-height/2;
    break;

    case 1: // ball bouncing
    // any code you might use to monitor the ball
    // what you had in draw before implementing this
    break;
}

If you want I can make a small ged demo of it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: ball back on paddle

Postby Nykos » Thu Jan 13, 2011 9:51 am

Thanks a lot, will try it today
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: ball back on paddle

Postby Nykos » Thu Jan 13, 2011 10:19 am

It worked, it's so cool, thanks a lot. I had to change the y value cause the ball wasredirected in the center of the paddle and still moving, but now all is good.

Just one more question, I have an animation playing when the ball is colliding with the bricks or the wall, everything works fine. But I wonder how could I play another animation just after the previous (the colliding one) is finished ? It's not really important but it could make a real good effect.

But once again thanks a lot, you don't imagine how much pain it was to have the ball out of the paddle.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: ball back on paddle

Postby schnellboot » Thu Jan 13, 2011 3:35 pm

there is an event called animation finished or something
this must help..
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest