having a picture when mouse is pressed
in
Programming Questions
•
2 years ago
Okay so I want a picture to appear and move when I click with the mouse in a spot here is what I have done so far but the code doesn't work:
TAB 1
PImage bg;
void setup()
{
size(768,480);
bg = loadImage("sky.png");
background(bg);
}
void setup()
{
size(768,480);
bg = loadImage("sky.png");
background(bg);
}
void draw()
{
if(mousePressed){
rocket1(381,357, 23, 23, 1);
}
}
{
if(mousePressed){
rocket1(381,357, 23, 23, 1);
}
}
TAB 2
PImage rocket;
void rocket1 (int xStart, int yStart, int xFinish, int yFinish, int Speed){
rocket = loadImage("rocket.png");
imageMode(CENTER);
image(rocket, xStart, yStart);
if(yFinish < 357){
if(xFinish < 381){
if(xStart > xFinish){
xStart=xStart - Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
if(xFinish > 381){
if(xStart < xFinish){
xStart=xStart + Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
}
if(yFinish > 357 & yFinish < 445){
if(xFinish < 381){
if(xStart > xFinish){
xStart=xStart - Speed;
}
if(yStart > yFinish){
yStart=yStart + Speed;
}
}
if(xFinish > 381){
if(xStart < xFinish){
xStart=xStart + Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
}
}
void rocket1 (int xStart, int yStart, int xFinish, int yFinish, int Speed){
rocket = loadImage("rocket.png");
imageMode(CENTER);
image(rocket, xStart, yStart);
if(yFinish < 357){
if(xFinish < 381){
if(xStart > xFinish){
xStart=xStart - Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
if(xFinish > 381){
if(xStart < xFinish){
xStart=xStart + Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
}
if(yFinish > 357 & yFinish < 445){
if(xFinish < 381){
if(xStart > xFinish){
xStart=xStart - Speed;
}
if(yStart > yFinish){
yStart=yStart + Speed;
}
}
if(xFinish > 381){
if(xStart < xFinish){
xStart=xStart + Speed;
}
if(yStart > yFinish){
yStart=yStart - Speed;
}
}
}
}
1