这是我的旧算法
def spawn(self):
self.position_move() #to adjust when the player is spawned
def position_move(self):
#gets called everytime the player moves
camera.x = -object.x+Window.size[0]/2.0
camera.y = -object.y+Window.size[1]/2.0
它运作良好,但当我接近一个角落时,我可以看到房间的“外面”。
我更新算法的全部目的是防止看到房间的“外面”:
def spawn(self): #when the player is first spawned
self.position_move() #to adjust when the player is spawned
def position_move(self):
#camera.x = -(top left x corner of camera coordinate)
#camera.y = -(top left y corner of camera coordinate)
#room_size= total room (or world) size
diff=(object.x-Window.size[0]/2)
if diff<0:
camera.x = object.x+diff
else:
diff=(object.x+Window.size[0]/2)-room_size[0]
if diff<0:
camera.x = -object.x+Window.size[0]/2.0
diff=(object.y-Window.size[1]/2)
if diff<0:
camera.y = diff+Window.size[1]/2
else:
diff=room_size[1]-(object.y+Window.size[1]/2)
if diff>0:
camera.y = -object.y+Window.size[1]/2.0
我对更新算法的想法是将相机转换回房间,它在房间外有多少。尽管出于某种原因我更新的算法有时会变得不稳定(飞走,或者甚至不跟随玩家)。
所以,是的,对于我认为是一项简单的任务来说,这有点复杂。有谁知道我的算法中有错误?
(我使用的框架有这样的坐标系)