hello i want to make my “rect” moove when i press “LEFT” but with this code the rect is mooving even if nothin is pressed.
(i used keyreleased because i want to press many keys at the same time)
what’s wrong??:
int x =100;
int y =100;
int x2 = 1000;
int y2 =50;
boolean[] keys;
void setup() {
size (1200, 600);
background(245, 72, 72);
keys=new boolean[1];
keys[0]=true;
}
void draw() {
background(245, 72, 72);
Player player1 = new Player(x, y);
Player player2 = new Player(x2, y2);
if (keys[0]=true) {
x=x+1;
}
text(player1.x, 50, 50);
}
void keyPressed() {
if (key==CODED) {
if (keyCode==LEFT)
keys[0]=false ;
}
}
void keyReleased() {
if (key==CODED) {
if (keyCode==LEFT)
keys[0]=false;
}
}
public class Player {
int x;
int y;
public Player(int px, int py) {
rect (px, py, 50, 100);
x = px;
y = py;
}
}