我在游戏开发中使用pygame与python导致了dable,我只是碰到了一堵砖墙。当我的一个实体尝试移动使用Vector2乘法时,我得到“致命的Python错误:(pygame降落伞)分段错误”。Vector2乘法导致蟒蛇中的分割错误
周围的错误时立即代码是这样的:
# destination and location are Vector2, and the difference is a Vector2
vec_to_destination = self.destination - self.location
distance_to_destination = vec_to_destination.length()
# normalize() returns a Vector2
heading = vec_to_destination.normalize()
# time_passed is a float and speed is an int
travel_distance = min(distance_to_destination, time_passed * self.speed)
# location is a Vector2 as well.
self.location += travel_distance * heading
# The previous line is where the Segmentation fault occurs.
# The equation looks like this with values filled in:
# Vector2(747, 183) += 6.435 * Vector2(-0.882763, 0.469818)
下可能有帮助。您可以复制,我通过键入以下为蟒蛇intepreter遇到的问题(Python 2.7版和pygame的1.9.2pre):
import pygame
from pygame.math import *
v = Vector2(747, 183)
v2 = 6.435 * Vector2(-0.882763, 0.469818)
v += v2
v
完整的代码重现该问题可以在这里找到: ftp.mattwjones .net 用户名:share1 密码:!share1
具体来说,在第一类'game_base.py'的第三种方法中,在'Zombies !!!'文件夹中。 – agf
哈!!!果然,这是做到了。我用“self.location = self.location + travel_distance * heading”替换了“self.location + = travel_distance * heading”,现在我的游戏运行良好。 Eryksun,添加与该信息的答复,我会接受它作为答案。 – viper34j
这应该作为对pygame IMO的错误提交。 –