• Create Account

#ActualNymall

Posted 22 February 2013 - 12:25 PM

Not a answer, as the above poster did it pretty well, just a caveat that's got me a couple of times(To hopefully make things easier on you).

When you're checking the size of the screen, remember to subtract the height from the graphic from the size of the screen. If you're tracking from the top of the graphic, it'll mean that the entire ball will disappear beyond the bound of the screen before reversing. I'd also suggest using a Boolean value to control the up down, so you can do something like this:

public void ballmove()
{
if(y >= screenheight){
ismoveup = false;
}
if(y <= 0 + ballheight){
ismoveup = true;
}
if(ismoveup == true){
y += 1;
} else {
y -= 1;
}
}
//This is assuming that your origin(0y) is the bottom of the screen
//you'll have to set the height of the ball in ballheight and the height of the screen in screenheight somewhere else


This isn't the most elegant solution, but should help you move forward.

#1Nymall

Posted 22 February 2013 - 12:23 PM

Not a answer, as the above poster did it pretty well, just a caveat that's got me a couple of times(To hopefully make things easier on you).

When you're checking the size of the screen, remember to subtract the height from the graphic from the size of the screen. If you're tracking from the top of the graphic, it'll mean that the entire ball will disappear beyond the bound of the screen before reversing. I'd also suggest using a Boolean value to control the up down, so you can do something like this:

public void ballmove()
{
if(y >= screenheight - ballheight){
ismoveup = false;
}
if(y <= 0){
ismoveup = true;
}
if(ismoveup == true){
y += 1;
} else {
y -= 1;
}
}
//This is assuming that your origin(0y) is the bottom of the screen
//you'll have to set the height of the ball in ballheight and the height of the screen in screenheight somewhere else


This isn't the most elegant solution, but should help you move forward.

PARTNERS