2016-01-18 49 views
1

移動部分一直在底部 如何使圖像在Python模式下移動以進行處理? 我嘗試了一切,沒有關於PyProcessing的教程。請幫助 另一種方式我想是: 如果的keyPressed(39):(39右箭頭鍵是ASCII) (然後什麼都)如何使圖像在Python模式下移動以進行處理?

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 
+0

你可以添加一個打印語句來幫助弄清楚發生了什麼?它會進入哪些if語句?當您繪製圖像時,「shipx」的價值是什麼? –

回答

0

爲了檢測箭頭鍵,你必須檢查的keyCode,不在keyPressed,所以試試這個:

if keyCode == LEFT: 
    shipx = shipx + 10 

另外,我不知道,如果你需要做這些步驟,但對於我的測試,if key == CODED是沒有必要的,我不得不在setup()移動變量聲明程序的頂部(對於圖像,先將它們設置爲None,然後致電loadImage()setup()

相關問題