Upload
daisuke-imai
View
59
Download
5
Embed Size (px)
Citation preview
CoffeeScript CoffeeScript はプログラミング言語のひとつである。コードはJavaScript のコードに変換される。 Ruby や Python、Haskell [1] から影響を受けたシンタックスシュガーの導入により、JavaScript に比べ簡潔さと可読性を向上させたほか、配列内包 (Array comprehensions) やパターンマッチといった機能を追加している。 CoffeeScript により、パフォーマンスを下げることなく、より短いコードでプログラムを記述することができる (JavaScript に比べ 1/3 程度の行数が削減できる)[2]。
「CoffeeScript」『フリー百科事典 ウィキペディア日本語版』(http://ja.wikipedia.org/)。2013年1月25日12時(日本時間)現在での最新版を取得。
<!DOCTYPE html> <html> <head> <meta http-‐equiv="Content-‐Type" content="text/html; charset=UTF-‐8" /> <script type="text/javascript" src="./enchant.js"></script> <script type="text/javascript"> enchant(); window.onload = function() { var game = new Game(320,320); game.preload('a.png'); game.onload = function() { var test = new Sprite(100,100); test.x = 10; test.y = 10; test.image = game.assets['a.png']; game.rootScene.addChild(test); }; game.start(); }; </script> </head> <body> </body> </html>
スプライト表示までの最低限のコード
enchant(); window.onload = function() { var game = new Game(320,320); game.preload('a.png'); game.onload = function() { var test = new Sprite(100,100); test.x = 10; test.y = 10; test.image = game.assets['a.png']; game.rootScene.addChild(test); }; game.start(); };
スプライト表示までの最低限のコード
enchant() window.onload = -‐> game = new Game(320,320) game.preload('a.png') game.onload = -‐> test = new Sprite(100,100) test.x = 10 test.y = 10 test.image = game.assets['a.png'] game.rootScene.addChild test game.start()
スプライト表示までの最低限のコード
var Star = enchant.Class.create(enchant.Sprite, { initialize: function() { enchant.Sprite.call(this, 16, 16); this.image = game.assets['icon0.gif']; this.frame = 30; this.x = 320; this.y = 160; this.speed = 3; this.addEventListener(Event.ENTER_FRAME, function() {
this.x -‐= this.speed; if (this.x < 0) { this.remove();
} });
}, remove: function() { delete this; }
});
スプライト継承のクラスのコード
class Star extends Sprite constructor: -‐> super 16, 16 @image = Game.instance.assets['icon0.gif'] @frame = 30 @x = 320 @y = 160 @speed = 3 onenterframe: (e) -‐> @x -‐= @speed if @x < 0 this.remove()
remove: -‐> delete this
スプライト継承のクラスのコード