level 6
self.circle = pygame.draw.circle(pygame.display.get_surface(), [255,0,0], [100 , 100], 30, 2) 可以画圆形
什么是动画精灵?Sprite么?精灵的话可以继承pygame.sprite.Sprite。也可以自己写。动画是精灵里的一个小件。只管显示。
打出来吧
# coding=utf-8
import pygame , sys , random
from pygame.locals import *
class Animation():
def __init__(self):
self.circle = None
self.x = self.y = 0
def draw(self):
r = random.randint(0 , 255)
g = random.randint(0 , 255)
b = random.randint(0 , 255)
self.circle = pygame.draw.circle(pygame.display.get_surface(), [r , g , b] , [self.x , self.y], 30, 2)
def play(self):
self.draw()
def setRect(self , rect):
self.x , self.y = rect[0] , rect[1]
class MySprite(pygame.sprite.Sprite):
def __init__(self , rect):
super(MySprite , self).__init__()
self.rect = pygame.Rect(rect)
self.animation = Animation() # 关于这个动画类怎么写?想要他咋样就咋样呗 。比如说你想画一个圆 就在里面加上第一句代码 . 想让他动 就在 Animation中的draw()里面放上你想要的动画
def update(self):
self.rect.x += 1. # 碰撞范围移动
self.animation.setRect(self.rect.topleft) # 将动画的rect绑定到sprite的rect
self.animation.play() # 播放你自己做的动画。play()里面的大体意思就是 不停的画 不停的运行
def main():
pygame.init();
screen = pygame.display.set_mode([800,600])
circle = MySprite([300,300,300,300])
while True:
screen.fill(0)
for event in pygame.event.get():
keys = pygame.key.get_pressed()
if event.type == QUIT or keys[K_ESCAPE]:
sys.exit()
circle.update()
pygame.display.update()
if __name__ == '__main__':
main()
这可能就是你想要的所谓的动画精灵 不知道我有没有理解错0 0
2016年03月03日 04点03分