Differences between revisions 2 and 7 (spanning 5 versions)
Revision 2 as of 2005-07-30 01:57:57
Size: 1464
Editor: flyaflya
Comment:
Revision 7 as of 2009-12-25 07:09:32
Size: 1518
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== PyGame ==
=== 简介 ===
## page was renamed from pygame
= PyGame =
== 简介 ==
Line 5: Line 6:
 * 缺点:图像必须读入surface后显示,占用内存多,不适合制作大型游戏
 * 官方站点: [http://www.pygame.org/]
=== 技巧 ====
 * 缺点:图像必须读入surface后显示,占用内存多,不适合制作大型游戏,blit算法过于单一。
 * 官方站点: [[http://www.pygame.org/]]
== 技巧 ==
Line 9: Line 10:
=== 代码段 === == 代码段 ==

PyGame

简介

  • 简述:用于游戏制作
  • 能力:有完备的控制、声音、显示模块,支持bmp,png等多种图像格式,自动载入Alpha通道,能显示复杂特效。
  • 缺点:图像必须读入surface后显示,占用内存多,不适合制作大型游戏,blit算法过于单一。
  • 官方站点: http://www.pygame.org/

技巧

代码段

  • 用一个surface填充另一个surface,很常用的功能,pygame里竟然没有,自己写一个。

   1 def fill_blit(source, dest, dRect, sRect = None ):
   2     if not sRect:
   3         sr = source.get_rect()
   4     else:
   5         sr = pygame.Rect(sRect)
   6     dr = pygame.Rect(dRect)
   7     
   8     for i in range(dr.height/sr.height):
   9         for j in range(dr.width/sr.width):
  10             dest.blit(source, (dr.x + j * sr.width, dr.y + i * sr.height), sr)
  11         if dr.width%sr.width != 0:
  12             left = dr.width%sr.width
  13             dest.blit(source, (dr.x + dr.width - left, dr.y + i * sr.height), (sr.x,sr.y,left,sr.height))
  14     
  15     #填边
  16     if dr.height%sr.height != 0:
  17         hleft = dr.height%sr.height
  18         for j in range(dr.width/sr.width):
  19             dest.blit(source, (dr.x + j * sr.width, dr.y + dr.height-hleft), (sr.x, sr.y, sr.width, hleft))
  20         if dr.width%sr.width != 0:
  21             left = dr.width%sr.width
  22             dest.blit(source, (dr.x + dr.width - left, dr.y + dr.height-hleft), (sr.x, sr.y, left, hleft))

PyGame (last edited 2009-12-25 07:09:32 by localhost)