1

移动部分一直在底部 如何在 Python 模式下移动图像进行处理?我尝试了所有方法,但没有关于 PyProcessing 的教程。请帮助我尝试的另一种方法是:如果keyPressed(39):(39是右箭头键是ASCII)(然后是什么)

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
4

1 回答 1

0

要检测箭头键,您必须检查 keyCode,而不是 keyPressed,所以试试这个:

if keyCode == LEFT:
    shipx = shipx + 10

另外,我不知道您是否需要执行这些步骤,但对于我的测试,if key == CODED没有必要,我不得不将变量声明setup()移到程序的顶部(对于图像,将它们设置为 None 在首先然后打电话loadImage()setup()

于 2017-04-04T07:56:52.570 回答