如何从 Python 中的精灵表中选择精灵图像? [英] How do you select a sprite image from a sprite sheet in Python?

查看:41
本文介绍了如何从 Python 中的精灵表中选择精灵图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想导入一个精灵表并选择一个精灵.我将如何在 Python/pygame 中执行此操作?

I want to import a sprite sheet and select one sprite. How would I do this in Python/pygame?

推荐答案

我做了这个,你可能会感兴趣:

I made this, it might interest you:

import pygame, sys
from pygame.locals import *

SCREEN_X=400
SCREEN_Y=400
#Screen size

SPRT_RECT_X=0  
SPRT_RECT_Y=0
#This is where the sprite is found on the sheet

LEN_SPRT_X=100
LEN_SPRT_Y=100
#This is the length of the sprite

screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y)) #Create the screen
sheet = pygame.image.load('C:\YOURFILE') #Load the sheet

sheet.set_clip(pygame.Rect(SPRT_RECT_X, SPRT_RECT_Y, LEN_SPRT_X, LEN_SPRT_Y)) #Locate the sprite you want
draw_me = sheet.subsurface(sheet.get_clip()) #Extract the sprite you want

backdrop = pygame.Rect(0, 0, SCREEN_X, SCREEN_Y) #Create the whole screen so you can draw on it

screen.blit(draw_me,backdrop) #'Blit' on the backdrop
pygame.display.flip()
#Draw the sprite on the screen

希望能帮到你

这篇关于如何从 Python 中的精灵表中选择精灵图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆