HTML5 2D 游戏引擎:Coffee2D
jopen
9年前
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'}