Loading...
Logo
Processing Forum
Hi,
 
I'm having a few problems. First of all, I'm a beginner, so this is all very easy, but I'm just not sure how to use it yet.
 

PImage img;
PImage img1;
PImage img2;
PImage img3;
PImage img4;
//PImage img5;
int temp;
int temp1;

void setup()
{
  size(500,500);
  background(220);
  img = loadImage("harryWand2.gif");
  img1 = loadImage("avada.jpg");
  img2 = loadImage("voldemort.gif");
  img3 = loadImage("expelliarmus.gif");
  img4 = loadImage("bird.gif");
}

getO()
{
  if (keyPressed)
  {
    if (key == 'o')
    {
      image(img4, temp - 170, temp1 - 147);
      temp = mouseX;
      temp1 = mouseY;
      delay(1000);
      temp--;
      temp1--;
    }
  }
}

void draw()
{
  background(220);
  image(img, mouseX, mouseY);
  if (keyPressed)
  {
    if (key == 'a')
    {
      image(img2, mouseX, mouseY);
      image(img1, mouseX - 330, mouseY - 420);
    }
  }
  if (mousePressed == true)
  {
    image(img3, mouseX - 330, mouseY - 420);
  }
}
 
So, I want, under key == 'o', for birds to appear and then move off screen. I can't work out how to make it update after every row and not after the loop is complete (I'm using draw()). Also, the program doesn't like temp-- or temp - 1 or temp -- 1, and I can't figure out how to subtract one from it.
 
Thank you!

Replies(1)



Hello,

you need to call getO within draw.

Otherwise the program does not see / use it.

Have after background
Copy code
  1. getO();


You need to initialize temp & temp1 in setup.
Write
Copy code
  1. temp=0;
  2. temp1=0;
in setup().

Don't use delay, delete the line
Copy code
  1. delay(1000);
please.


The flying.
Now to the hard part: The flying. Processing doesn't update the screen immediately, but only once at the end of draw(). The function draw() loops and therefore gets called about 60x per second. But because it's draws only at the end of draw you have to have your fly movement within draw.
Thus getO() must start the fly process but can not run it.
So, this
Copy code
  1.       image(img4, temp - 170, temp1 - 147);
belongs into draw();
but with a condition like: When flying
Copy code
  1. if (flying)  {
  2.       image(img4, temp - 170, temp1 - 147);
  3.       temp--;
  4.       temp1--;
  5. }

in getO you set flying to true,
when they left the screen you set flying to false.

Don't have this in getO:
Copy code
  1.       temp--;
  2.       temp1--;


I know it's not so easy, but we'll help.

Unfortunately we can not run the code because of the images.


Greetings, Chrisir