1

The movement part is all the way at the bottom How do I make an image move in Python Mode for Processing? I tried everything and there are no tutorials on PyProcessing. Please Help another way i tried is: if keyPressed(39): (39 is right arrow key is ASCII) (and then what ever)

def setup():
    global back, canvash, canvasw, cornerpointx, cornerpointy
    global invader, invaderx, invadery, invaderw, invaderh
    global ship, shipx, shipy, shipw, shiph
    global beam, beamw, beamh

    shipy = 0
    shipx = 0
    canvasw = 800
    canvash = 800
    shipw = 100
    shiph = 100
    shipx = 0
    shipy = 0
    beamw = 50
    beamh = 900
    invaderw = 50
    invaderh = 50
    size( canvasw,canvash )
    back = loadImage( "back.png" )
    ship = loadImage( "ship.png" )
    invader = loadImage( "alien.png" )

def draw():
    global back, canvash, canvasw, cornerpointx, cornerpointy
    global invader, invaderx, invadery, invaderw, invaderh
    global ship, shipx, shipy, shipw, shiph
    global beam, beamw, beamh

    background = image(back, 0, 0, canvasw, canvash)
    image(ship, shipx, shipy, shipw, shiph)
    image(invader, 100, 350, invaderw, invaderh)

def keyPressed():
    global back, canvash, canvasw, cornerpointx, cornerpointy
    global invader, invaderx, invadery, invaderw, invaderh
    global ship, shipx, shipy, shipw, shiph
    global beam, beamw, beamh

    if key == CODED:
        if keyPressed == LEFT:
            shipx = shipx + 10
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
DmesticG
  • 11
  • 1
  • Can you add a print statement to help figure out what's going on? Which of those if statements does it enter? What is the value of `shipx` when you draw the image? – Kevin Workman Jan 18 '16 at 22:39

1 Answers1

0

To detect the arrow keys you must check keyCode, not keyPressed, so try this:

if keyCode == LEFT:
    shipx = shipx + 10

Also, I don't know if you'll need to do these steps but for my testing, if key == CODED wasn't necessary and I had to move the variable declarations in setup() to the top of the program (for the images, set them to None at first then call loadImage() in setup())

MinteZ
  • 86
  • 4