[英]8 Queens (pyglet-python)
我正在尝试在 pyglet 上制作 8 个皇后游戏。 我在窗口上成功生成了 board.png。 现在,当我在上面粘贴 Queen.png 图像时,我希望它只显示 Queen 而不是白色部分。 我使用photoshop删除了白色部分,但正如我在pyglet中的board.png上所说的那样,它再次显示白色部分请帮忙。
import pyglet
from pyglet.window import Window, mouse, gl
# Display an image in the application window
image = pyglet.image.Texture.create(800,800)
board = pyglet.image.load('resources/Board.png')
queen = pyglet.image.load('resources/QUEEN.png')
image.blit_into(board,0,0,0)
image.blit_into(queen,128,0,0)
# creating a window
width = board.width
height = board.height
mygame = Window(width, height,
resizable=False,
caption="8 Queens",
config=pyglet.gl.Config(double_buffer=True),
vsync=False)
# Making list of tiles
print("Height: ", board.height, "\nWidth: ", board.width)
@mygame.event
def on_draw():
mygame.clear()
image.blit(0, 0)
def updated(dt):
on_draw()
pyglet.clock.schedule_interval(updated, 1 / 60)
# Launch the application
pyglet.app.run()
这些是图像:
你的图像是一个矩形。 因此,无论您做什么,您的女王周围都会有一片空白。
我会推荐一些hacking(它不是很漂亮)并创建两个皇后版本:queen_yellow 和queen_black。 每当女王站在黄色瓷砖上时,显示queen_yellow,否则显示queen_black。
要确定一个瓦片是否为黄色瓦片(使用具有 x 和 y 坐标的矩阵,其中 y 的顶部值为 0,x 的最左侧值为 0):
if tile_y%2=0: #is it an even row?
if tile_x%2=0: #is it an even column?
queentype = queen_yellow
else:
queentype = queen_black
else: #is it an uneven row?
if tile_x%2!=0: #is it an uneven column?
queentype = queen_yellow
else: queentype = queen_black
希望有帮助,Narusan
首先,请确认没有背景(您可以使用 GIMP)。 一旦完成,请继续:
由于它是 PNG 图像,您不能将其放在窗口上,因为它会失去透明度。 您需要从 pyglet 导入 PNGImageDecoder,例如
from pyglet.image.codecs.png import PNGImageDecoder
然后用它来加载PNG图像
kitten = pyglet.image.load('kitten.png', decoder=PNGImageDecoder())
最后通过使用将其绘制在窗口上
kitten.draw()
,在指定你想要它们的 x 和 y 坐标之后。
可以在此处找到上述文档。
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.