#How to move a PShape

9 messages · Page 1 of 1 (latest)

unkempt timber
#

I may be doing something off because nothing I put in the case seems to have any effect on the ship at all.

#
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;
    }
  }
}
chrome tinsel
#

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;
    }
  }
}
unkempt timber
#

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.

chrome tinsel
#

Most people ignoring this option. I personally like it to mark this as solved.

unkempt timber
#

!solved

#

How do I do it?☝️ This didn't work and I don't see an edit tag either.