We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › simple bounds issue, and other queries
Page Index Toggle Pages: 1
simple bounds issue, and other queries (Read 644 times)
simple bounds issue, and other queries
Oct 13th, 2005, 9:03am
 
Hello.

I'm having a small issue with a little pong clone I'm playing around with.
Basically I'm trying to figure out how I can get the paddle to start in the middle until the mouse is on the frame.

I've done similar games in Flash before, but Processing seems to read the mouse even outside the frame.

Here's the code:
Code:

void bar_top()
{  
 

 noStroke();
 //stroke(255);
 fill(255,0,102);
 //102,204,0
 //153,204,0
 rectMode(CENTER);
 rect(xb,yb,wb,hb);
 rect(xb,yb+5, wb/5, hb);
 rect(xb,yb+10, wb/10, hb);
 println(xb);
 
   if (xb >= 28 && xb <= 377)
 {
  xb = mouseX;
 }
}

So what im trying to do is keep it in the bounds above.
xb = 200, but that only works for one frame, then its reset to 0.

Any suggestions?

Maybe there's a good pong clone I could take a look at that someone knows?
I'm going to also have the ball start off the paddle like Pong.

I was thinking about doing that with a boolean, or variable triggered on Space Bar or something like that.

Any suggestions would be fantastic.

Cheers
Re: simple bounds issue, and other queries
Reply #1 - Oct 13th, 2005, 1:13pm
 
you could test mouseX to see if it's outside the screen, e.g. if mouseX < 0 || mouseX >=width || mouseY <0 || mouseY>=height and if so, don't use it.
Page Index Toggle Pages: 1