HTML5 2D 游戲引擎:Coffee2D

jopen 10年前發布 | 14K 次閱讀 Coffee2D 游戲開發

Coffee2D 是一個 HTML5 游戲引擎,它將開發 HTML5 Canvas 游戲中大量的工作抽象出來,例如 CoffeeScript 特性(如 class 關鍵字)來更好的與游戲和 CoffeeScript 集成。

Coffee2D 當前提供:

  • 簡單場景圖

  • 精靈渲染

  • 事件處理

  • 動畫

  • Isometric 地圖

組件:

class Card extends Component
  constructor: (@suit, @value) ->
    super()
    @setSize(50, 80)
    # the rectangle will be drawn automatically
    @addChild new Rect 0, 0, @size.w, @size.h, 'white'

  update: (dt) ->
    # dt is delta time passed since last update
    # (update stuff...)
    super()

  draw: (ctx) ->
    # ctx is the canvas context associated with this scene
    # (draw additional stuff other than the rectangle...)
    super()

事件處理:

# event origin is automatically set to unit
unit.dispatchEvent {type: 'kill', target: enemy}
enemy.addListener 'kill', (evt) -> if evt.target == enemy then enemy.die()

# can also fire events from Event class, origin will not be set
Event.dispatchEvent {type: 'init'}

項目主頁:http://www.baiduhome.net/lib/view/home/1433664758302

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!