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 › Adding Gravity to PImages
Page Index Toggle Pages: 1
Adding Gravity to PImages? (Read 605 times)
Adding Gravity to PImages?
Sep 22nd, 2007, 8:23pm
 
Hey, I have a question. How would I got about making a PImage after clicking, and then having it fall to the bottom of the screen as an object with bounce and what not? The goal is to have someone click a point, and an egg appears, and then falls to the bottom. After clicking on the egg, it then hatches. I'm stuck on implementing gravity to a PImage of the egg. How would I go about doing this? Heres the code so far for the egg image:



void draw() {
 size(300,300);
 fill(255);
}
void mouseReleased() {
 if (mouseY < 150){
  PImage b;
b = loadImage("egg1.gif");
image(b, mouseX-27, mouseY-30);
 }
 
 
}


This is so the egg does not appear under the halfway mark of the screen, so it has time to have a dropping animation.
Re: Adding Gravity to PImages?
Reply #1 - Sep 30th, 2007, 3:38am
 
Hi Yodan
this might help - these go from left to right and have a very small simple bounce at the end but you could take the code & adapt it to go top to bottom with more bounce.

http://www.dement.org/moving_forest/arrows/arrows07.html

Linda
Re: Adding Gravity to PImages?
Reply #2 - Oct 1st, 2007, 3:56pm
 
Hi Yodan. Try something like this :

- create an egg-class with a "fall()" method and X, Y and deltaY values.
- when user clicks, create an egg object at mouse position.
- in your draw loop, iterate your eggs collection and run their "fall()" method.

You may start with something like this :
Class Egg {
 float X, Y, deltaY;
 
 fall() {
   deltaY += 0.2;
   Y += deltaY;
 }
 
}
Page Index Toggle Pages: 1