简体   繁体   English

即使我定义了名称“delta_scroll”,也没有定义它?

[英]name 'delta_scroll' is not defined even though I defined it?

so I am trying to make my enemy not scroll with my camera when it moves left and right所以我试图让我的敌人在左右移动时不会用我的相机滚动

I someone helped me make a function to stop my enemy from scrolling all it suppose to do is not make my enemy scroll example vid我有人帮我制作了一个 function 来阻止我的敌人滚动它所要做的就是不让我的敌人滚动示例vid

def onscroll(enemying, delta_scroll): 
    for enemys in enemying:
        enemys.position = (enemys.position[0] - delta_scroll, enemys.position[1])

then on my main loop I called that function so my enemy doesnt scroll with my screen然后在我的主循环中,我调用了 function 所以我的敌人不会随着我的屏幕滚动


    # camera left and right movement
    if playerman.y < 250:
        playerman.y += 1
        for enemys in enemying:
            enemys.y += delta_scroll


but for some reason I keep getting the same error但由于某种原因,我不断收到同样的错误


name 'delta_scroll' is not defined

Enemy Class敌人 Class

my full code我的完整代码

Quick tip- there are a TON of pg.image.load("myImg.png") commands.快速提示 - 有大量pg.image.load("myImg.png")命令。 here is a better way of doing it:这是一种更好的方法:

standingright = []
for i in range(1, 16):
    imgPath = "d"+str(i)+".png"
    img = pg.image.load(imgPath)
    standingright.append(img)

This is a much more concise way of loading the images.这是一种更简洁的图像加载方式。 It will result in the exact same list of images in the exact same order, but I thought I would mention it to you because it will make your code much neater.它将以完全相同的顺序生成完全相同的图像列表,但我想我会向您提及它,因为它会使您的代码更加整洁。

About the issue at hand: I searched your code for mentions of delta_scroll, and found it being used, but never defined.关于手头的问题:我在您的代码中搜索了提到 delta_scroll 的内容,发现它正在使用,但从未定义。 Also I saw you defined the function "onscroll", but never used it.我还看到您定义了 function “onscroll”,但从未使用过它。 Are you getting these two mixed up perhaps?你是不是把这两个弄混了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM