我“移动”我的播放器,让除了背景以外的所有东西都存储在一个要碰撞和移动的对象列表中。我使用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)
我希望当我尝试放置一个块时,它会和其他块对齐,即使我移动一点点。 有谁能提供一个解决方案,甚至是一个开始
目前没有回答
相关问题 更多 >
编程相关推荐