Created
August 14, 2018 11:54
-
-
Save shiroutosan/c9ac30756783c9c4335f8eb6d3635854 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pygame.locals import * | |
import pygame | |
class player(): | |
def __init__(self,x,y,img): | |
self.x = x | |
self.y = y | |
self.image = pygame.image.load(img) | |
self.imagelist = self.split_image(self.image) | |
def split_image(self,image): | |
"""128x128のキャラクターイメージを32x32の16枚のイメージに分割 | |
分割したイメージを格納したリストを返す""" | |
imageList = [] | |
dots = 32 | |
for i in range(0, 128, dots): | |
for j in range(0, 128, dots): | |
surface = pygame.Surface((dots, dots)) # 32*32のSurfaceを生成 | |
surface.blit(image, (0, 0), (j, i, dots, dots)) | |
surface.set_colorkey(surface.get_at((0, 0)), RLEACCEL)#座標(0,0)の色を透過色に設定 | |
surface.convert() | |
imageList.append(surface)#リストに追加 | |
return imageList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment