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 & HelpSyntax Questions › Re: Squares Game Problems
Page Index Toggle Pages: 1
Re: Squares Game Problems (Read 697 times)
Re: Squares Game Problems
Apr 18th, 2010, 1:12pm
 
Quote:
size(clouds.width, clouds.height);


This could be your problem.  size should always be the first line in setup and IIRC you shouldn't pass variables to it but real numbers.  Try hard-coding the pixel size of your image into it and moving it up to the beginning of setup...

I haven't looked through the rest of the code thoroughly, but at a glance it appears OK (unable to test as I don't have the images).
Re: Squares Game Problems
Reply #1 - Apr 18th, 2010, 2:22pm
 
OK - on closer inspection I see the problem.

The thing about size still stands - not following that rule can lead to weird and unexplainable problems down the line; which is why I saw that and assumed it was the cause here.  In actual fact the issue here is much more mundane:

Quote:
class Bear{
 float r;
 float x,y;

 Bear(float tempR){
   r=tempR;
   x=mouseX;
 y=mouseY;

 }

 void displayBear(){
   //Draw bounding-box for bear image.
   ellipse(mouseX,mouseY+3,40,40);
   //Draw bear icon to follow mouse.
   image(bo,mouseX,mouseY, bo.width*.4, bo.height*.4);
 }

 //Function to return true or false based on if bear intersects
 //a honey pot
 boolean intersect(Honey h){
   float distance=dist(x,y,h.x,h.y); //Calculate distance
   if(distance<r+h.r){ //Compare distance to sum of radii
     return true;
   }
   else {
     return false;
   }
 }
}


You set the bear's x and y properties to MouseX/Y only once: at the moment of the bear object's creation... But then don't update it; so it's checking collisions against the position of the mouse when the sketch was run.  Things look like they're working because of course you're drawing the bear by referencing mouseX/Y directly.  Instead try this in your original code:

Code:
void displayBear(){
   // Update x/y to current mouse position
// (this will then be used in the hit test)
   x=mouseX;
   y=mouseY;
   //Draw bounding-box for bear image.
   ellipse(x,y+3,40,40);
   //Draw bear icon to follow mouse.
   image(bo,x,y, bo.width*.4, bo.height*.4);
 }
Re: Squares Game Problems
Reply #2 - Apr 18th, 2010, 2:30pm
 
Resolved. Thanks for the help!
Page Index Toggle Pages: 1