We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Forum Team,
Can you help me understand the logic in a simple way to use the 's' key to load image 1 in a frozen in-place position and make the left and right direction images (images 2 and 3) temporarily disappear. (Here I already have the left and right images working with 'a' and 'd' keys.)
//images https://drive.google.com/file/d/1ZcnENU-SLzeiL8q4HMOxoNRBcAfBmEqy/view?usp=sharing
https://drive.google.com/file/d/1njKnrunrPtZIy4nXBfO2XcYqqsJx48k0/view?usp=sharing
https://drive.google.com/file/d/1atFLINdpkB8FK6mocuXl6Cjl4m67s0Ia/view?usp=sharing
int x1 = width/2; //START CHARACTER IN MIDDLE
int t = 255;
int r = 0;
boolean on = false;
PImage img1;
PImage img2;
PImage img3;
void setup(){
size(800,600);
smooth();
strokeWeight( 2 );
img1 = loadImage ("Mint3.png"); //CENTER IMAGE CURRENTLY NOT LOADING AFTER MOVEMENT BEGINS
img2 = loadImage ("mintright.png");
img3 = loadImage ("mintleft.png");
}
void draw(){
background( 255 );
tint (255,t);
image(img1, x1, 300, 250,200);
println ("x1=",x1);
if (keyPressed) {
//go right
if (key == 'd' || key == 'D') {
t = 0;
noTint ();
image(img2, x1, 300, 250,200);
x1 += 1;
//go left
} else if (key == 'a' || key == 'A') {
t = 0;
noTint ();
image(img3, x1, 300, 250,200);
x1 -= 1;
}
} // <--close keyPressed
} // <-- close draw
Answers
Write it out in English first, then convert this to code.
Hello TfGuy44!
Thanks for working with me!
Here's my revision based on your breakdown. Is there a simple way to make the states be continuous until the next key pressed?
make a variable int state that indicates the current image (0,1,2)
if a state = 0
with b state = 1
etc.
in draw say outside if keypressed
Thank you Chrisir!!!!!!!!!!!
;-)