等距瓷砖选择公式略有偏离

时间:2019-10-23 16:44:44

标签: python selection tile pyglet isometric

我几乎使等轴测图选择公式起作用,但似乎略有偏离:http://prntscr.com/pn3gbv

当鼠标悬停在图块的上半部分时,它似乎工作正常,但是当鼠标移至下半部分时,它会跳至下一个图块:http://prntscr.com/pn3hpx
here's展示问题的视频)

它也不占相机,我也不知道如何实现。因此,对此也将提供一些帮助。

以下是使用的相关代码,here's a minimal executable example以及使用的图像资源:

path.png

import pyglet

tile_width_half = 84/2
tile_height_half = 51/2

class Game(pyglet.window.Window):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.island = Island()
        self.camera = Camera()
        self.selection = pyglet.sprite.Sprite(pyglet.image.load("path.png"))
    def on_mouse_motion(self, x, y, dx, dy):
        global tile_height_half,tile_width_half
        j = int((x / tile_width_half + y / tile_height_half) / 2)
        i = int((y / tile_height_half - x / tile_width_half) / 2)
        self.selection.x = (j-i)*tile_width_half
        self.selection.y = (j+i)*tile_height_half
    def on_draw(self):
        self.clear()
        self.island.draw()
        self.selection.draw()
    def on_key_press(self, symbol, modifiers):
        if symbol == key.A:
            self.camera.left = True
        if symbol == key.W:
            self.camera.up = True
        if symbol == key.D:
            self.camera.right = True
        if symbol == key.S:
            self.camera.down = True
        if symbol == key.ESCAPE:
            pyglet.app.exit()
    def on_key_release(self, symbol, modifiers):
        if symbol == key.A:
            self.camera.left = False
        if symbol == key.W:
            self.camera.up = False
        if symbol == key.D:
            self.camera.right = False
        if symbol == key.S:
            self.camera.down = False
    def update(self,dt):
        for tile in self.island.all_sprites:
            tile.x += self.camera.position[0]
            tile.y += self.camera.position[1]
        self.camera.move()


if __name__ == '__main__':
    game = Game(800,600,"title")
    pyglet.clock.schedule_interval(game.update,1/60)

    pyglet.app.run()

0 个答案:

没有答案
相关问题