#How to move a PShape
9 messages · Page 1 of 1 (latest)
int shipX = 0;
int shipY = 0;
void setup() {
size (800, 800);
}
void draw() {
drawShip();
moveShip();
}
void drawShip() {
shipX = width/2;
shipY = height/2;
ship = createShape(TRIANGLE, shipX-100, shipY+10, shipX, shipY, shipX-100, shipY-10);
shape(ship);
}
void moveShip() {
if (keyPressed) {
switch(key) {
case 'w':
//move ship up
break;
case 's':
//move ship down
break;
}
}
}
Your problem is simple, look at your drawShip method, on the first two lines you overwrite any changes made in the moveShip method.
Simple solution, move this lines to the setup method.
PShape ship;
int shipX = 0;
int shipY = 0;
void setup() {
size (800, 800);
shipX = width/2;
shipY = height/2;
}
void draw() {
drawShip();
moveShip();
}
void drawShip() {
ship = createShape(TRIANGLE, shipX-100, shipY+10, shipX, shipY, shipX-100, shipY-10);
shape(ship);
}
void moveShip() {
if (keyPressed) {
switch(key) {
case 'w':
//move ship up
break;
case 's':
//move ship down
break;
}
}
}
Thank you🤓
I hate it when it is right in front of my face.
Do I need to mark this as solved?
I don't see anyone else marked as such.
Most people ignoring this option. I personally like it to mark this as solved.