Vector2乘法导致python中的Segmentation Fault

时间:2011-08-19 04:02:35

标签: python pygame

我在游戏开发中使用pygame与python进行dable,我只是碰到了一堵砖墙。当我的一个实体尝试使用Vector2乘法移动时,我得到“致命的Python错误:( pygame parachute)Segmentation Fault”。

错误的直接代码是:

# 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)

以下内容也可能有所帮助。您可以通过在python 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

0 个答案:

没有答案