Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8295356
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类:

2007-04-05 10:40:24

用PureBasic做简单的游戏开发是个不错的主题,他提供了非常简单明了的方式让我们却编写游戏,这个例子是一个显示精灵的例子,我写的注释,可以参考一下。
 


;初始化Sprite以及Keyboard
If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 or later", 0)
  End
EndIf


;打开一个640*480*16的屏幕,标题为Sprite
If OpenScreen(640, 480, 16, "Sprite")

 ; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format)
;加载一个图片,实际上是24位图片,BMP不支持16位
LoadSprite(0, "Data\PureBasic.bmp", 0)
;复制一个与0一样的Sprite
CopySprite(0,1,0)
  
; Draw some red line on our sprite
;在精灵上面绘制一些红色线条
If StartDrawing(SpriteOutput(1))
   ;设置前景色为红色
   FrontColor(RGB(255, 0, 0))
   For k = 0 To SpriteHeight(1) Step 2
      Line(0, k, SpriteWidth(1), 0)
    Next
    StopDrawing()
  EndIf

  Repeat
    
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    ;页面翻转
    FlipBuffers()
    ;清除屏幕
    ClearScreen(RGB(0,0,0))
    
    ; Draw our sprite
    ;剪辑精灵,也就是自定义精灵大小,以裁剪方式?
    ClipSprite(0, 0, 0, x, x/8)
    ;显示精灵
    DisplaySprite(0, x, 100)
    DisplaySprite(1, x, x)
    DisplaySprite(0, 600-x, x)
    x+1
    ;更新键盘状态
    ExamineKeyboard()
  Until x > 500 Or KeyboardPushed(#PB_Key_Escape) ;按键
  
Else
  MessageRequester("Error", "Can't open a 640*480 - 16 bit screen !", 0)
EndIf

End

阅读(2982) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~