我通过将除背景之外的所有内容存储在对象列表中来“移动”我的播放器,以使其碰撞和移动。当我移动并尝试将它们偏离中心时,我使用round((touch.location.x - (self.newblockhouse.size.x / 2)) / self.newblockhouse.size.x) * self.newblockhouse.size.x + self.newblockhouse.size.x / 2) - round(self.posmarker.position.x - self.newblockhouse.size.x / 2)
放置对象以使其与网格对齐。
我正在运行Pythonista,以便可以在外出时进行处理。
我的建筑代码
self.newblockhouse = Blocks(self.listtomove)
self.newblockhouse.size = get_screen_size().x / 10, get_screen_size().y / 10
self.newblockhouse.position = (round((touch.location.x - (self.newblockhouse.size.x / 2)) / self.newblockhouse.size.x) * self.newblockhouse.size.x + self.newblockhouse.size.x / 2) - round(self.posmarker.position.x - self.newblockhouse.size.x / 2), round((touch.location.y - (self.newblockhouse.size.y / 2)) / self.newblockhouse.size.y) * self.newblockhouse.size.y + self.newblockhouse.size.y / 2
self.add_child(self.newblockhouse)
self.listtomove.append(self.newblockhouse)
运动
for p in self.listtomove:
p.directionx = 0 - p.speed
试图创建一个对象来存储“相机”位置
class DebugMarker(SpriteNode): # for finding the position of the grid
def __init__(self):
self.directionx = 0
self.directiony = 0
self.offsetfound = 0
self.size = get_screen_size().x / 10, get_screen_size().y / 10
def updateblocks(self):
self.position = self.position.x + self.directionx, self.position.y + self.directiony
self.offsetfound = self.offsetfound + self.directionx
print(self.offsetfound)
尝试使用此位置信息来偏移网格
self.newblockhouse = Blocks(self.listtomove)
self.newblockhouse.size = get_screen_size().x / 10, get_screen_size().y / 10
self.newblockhouse.position = (self.posmarker.offsetfound + round((touch.location.x - (self.newblockhouse.size.x / 2)) / self.newblockhouse.size.x) * self.newblockhouse.size.x + self.newblockhouse.size.x / 2) - round(self.posmarker.position.x - self.newblockhouse.size.x / 2), round((touch.location.y - (self.newblockhouse.size.y / 2)) / self.newblockhouse.size.y) * self.newblockhouse.size.y + self.newblockhouse.size.y / 2
self.add_child(self.newblockhouse)
self.listtomove.append(self.newblockhouse)
我希望当我尝试放置一个积木时,它会与其他积木对齐,即使我移动了一点点。 谁能提供解决方案?