在相同的“级别”上绘制东西。在Pygame中
我正在尝试在Pygame上制作纸牌,我想绘制所有在其他卡后绘制的圆柱底部的卡片。有没有办法更改绘制图像的顺序?我的意思是像一种方法更改我的draw_window函数中的顺序
。 noreferrer“>
import pygame
import os
#Fixa så att man flyttar flera kort när man flyttar högsta
#Fixa så att korten inte hamnar på varandra
#fixa så att man kan lägga kungen på en tom yta
#fixa blandad kortlek
#fixa fixa kort som ligger med baksidan upp
def draw_window():
WIN.blit(RESIZED_BACKGROUND, (0, 0))
WIN.blit(RESIZED_AXEL, (CARD3.xpos, CARD3.ypos))
WIN.blit(RESIZED_HDAM, (CARD1.xpos, CARD1.ypos))
WIN.blit(RESIZED_RKUNG, (CARD2.xpos, CARD2.ypos))
pygame.display.update()
def main():
clock = pygame.time.Clock()
run = True
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONUP:
mousepos = pygame.mouse.get_pos()
clicked_card = clicked_on_card(mousepos) #Kollar om kortet är klickbart
if clicked_card is not None and is_moveable(clicked_card, LIST_OF_CARDS) is not None:
move_card(clicked_card, parent_card)
draw_window()
pygame.quit()
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以做到这一点。该代码通过将卡作为单独的项目进行管理使其变得困难。
将它们列入列表,然后绘制列表将很好地工作。如果您想要特定的订购,
sort()
列表。按下 space 时,下面的示例代码将显示的卡重新订购。它通过对卡列表进行排序,而不是单独操作卡片。在下面,我将简单的类创建
card
类型。然后创建一些卡片&放入清单。要在列中绘制卡片,()循环在卡片列表上迭代,设置其位置,然后将其绘制到屏幕上。可能您需要游戏中每一张卡片的列表。
There's lots of ways to do this. The code is making it difficult by managing the cards as separate items.
It would work well to put them into a list, and then draw the list. If you want a specific ordering,
sort()
the list. The example code below re-orders the displayed cards when space is pressed. It does this by sorting the list of cards, rather than operating on the cards individually.Below I make a simple class to create a
Card
type. A few cards are then created & put into a list. To draw the cards in a column, afor()
loop iterates over the list of cards, setting their position and then drawing them to the screen.Probably you want a list for each column of cards in your game.