Skip to content

Instantly share code, notes, and snippets.

@wataruru35
Last active December 14, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wataruru35/5023365 to your computer and use it in GitHub Desktop.
Save wataruru35/5023365 to your computer and use it in GitHub Desktop.
enchant.js クリックするとスプライトがフェードアウト
enchant();
var SCREEN_WIDTH =320;
var SCREEN_HEIGHT =320;
window.onload = function() {
// ゲームオブジェクトを作成する
game = new Game(SCREEN_WIDTH, SCREEN_HEIGHT);
// fps(1秒あたりの画面の描画回数)を設定する(省略時は「30」)
game.fps = 16;
// ゲームで使用する画像ファイルを指定する
game.preload('image/betty.png');
// ファイルのプリロードが完了したときに実行される関数
game.onload = function() {
// ゲームのメイン処理
//ゲームの背景の色を設定
game.rootScene.backgroundColor = "#ffbbbb";
//スプライトを作成
var sprite = new Sprite(48,48);
sprite.image = game.assets["image/betty.png"];
sprite.frame = 3;
sprite.x = 320/2;
sprite.y = 320/2;
sprite.opacity = 1;
//rootSceneにスプライトを表示
game.rootScene.addChild(sprite);
//タッチイベントリスナー
sprite.ontouchstart = function(){
//frameアニメーション
this.onenterframe = function(){
//フェードアウト
this.opacity -= 0.25;
//フェードアウトが完了したらスプライトを削除
if(this.opacity <= 0){
this.parentNode.removeChild(this);
}
}
};
};
// ゲームスタート
game.start();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment