移动部分一直在底部 如何在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
答案 0 :(得分:0)
要检测箭头键,您必须检查keyCode,而不是keyPressed,所以试试这个:
if keyCode == LEFT:
shipx = shipx + 10
此外,我不知道您是否需要执行这些步骤,但对于我的测试,if key == CODED
不是必需的,我必须将setup()
中的变量声明移到顶部该程序(对于图像,首先将它们设置为无,然后在loadImage()
中调用setup()
)