すごろくをつくろうと思って、まずつくったサイコロです。
デザインは、娘が厚紙で作ったサイコロをそのまま再現しました。
猫がサイコロを転がすのかと思いきや、いっしょにぐるぐる転がっているだけというところがポイントです。
苦労したところは、音です。ドラムロールの音を長く鳴らして、振ったところで止めるということをしたかったのですが、どうやってもうまく制御できないので、断念しました。音についてはいろいろ難しいところがあるようです。
// Main console.log("Hello EnchantJS!!"); var assets = [ "images/title.png",// タイトル "images/cf307/nekosai128abc.png", "sounds/cf307/drum-roll1.mp3", "sounds/cf307/roll-finish1.mp3", "sounds/cf307/cat-cry1.mp3", ]; function gameStart(){// ゲーム画面 scene = gameManager.createGameScene(); core.replaceScene(scene); core.resume(); //========== // ここから //========== scene.backgroundColor = "#FADCE9"; // サイコロ var sai = new ExSprite(128, 128); sai.image = core.assets["images/cf307/nekosai128abc.png"]; sai.x = 320 / 2 - 128 / 2; sai.y = 480 / 2 - 128 / 2; sai.originY = 0; scene.addChild(sai); // サイコロ // タッチするとサイコロを振る scene.addEventListener(Event.TOUCH_START,function(){ var sound1 = core.assets["sounds/cf307/drum-roll1.mp3"].clone(); sound1.play(); scene.tl.delay(32).then(function(){ sound1.stop(); }); //sound1.src.loop = true; // サイコロが下にあるとき(回ってないとき) if(sai.y == 480 / 2 - 128 / 2){ console.log("回ってないとき"); sai.tl.moveBy(0, -150, 3, enchant.Easing.QUART_EASEIN); sai.tl.moveTo(320 / 2 - 128 / 2, 480 / 2 - 128 / 2 - 100, 2); sai.frame = [0, 1, 2, 3, 4, 5]; sai.scale(0.8, 0.8); } // 上にあるとき(回っているとき) if(sai.y == 480 / 2 - 128 / 2 - 100){ console.log("回っているとき"); sai.tl.moveTo(320 / 2 - 128 / 2, 480 / 2 - 128 / 2, 5, enchant.Easing.BOUNCE_EASEOUT);//and().scaleTo(1.2, 1.2, 0); sai.tl.scaleTo(1, 1, 0); sound1.stop(); var sound = core.assets["sounds/cf307/roll-finish1.mp3"].clone(); sound.play(); sai.tl.delay(5).then(function(){ var sound2 = core.assets["sounds/cf307/cat-cry1.mp3"].clone(); sound2.play(); }); // さいころの目 var s0 = getRandom(1, 6); if(s0 == 1){ console.log("1"); sai.frame = [0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, null]; } if(s0 == 2){ //sai.frame = [7]; console.log("2"); sai.frame = [12, 12, 12, 12, 12, 12, 12, 12, 7, 7, 7, 7, 7, 7, 7, 7, 7, 12, null]; } if(s0 == 3){ //sai.frame = [8]; console.log("3"); sai.frame = [13, 13, 13, 13, 13, 13, 13, 13, 8, 8, 8, 8, 8, 8, 8, 8, 8, 13, null]; } if(s0 == 4){ //sai.frame = [9]; console.log("4"); sai.frame = [3, 3, 3, 3, 3, 3, 3, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 3, null]; } if(s0 == 5){ //sai.frame = [10]; console.log("5"); sai.frame = [14, 14, 14, 14, 14, 14, 14, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, null]; } if(s0 == 6){ //sai.frame = [11]; console.log("6"); sai.frame = [15, 15, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11, 11, 11, 11, 11, 15, null]; } } }); //========== // ここまで //========== } function getRandom(start, end) { return start + Math.floor( Math.random() * (end - start + 1)); } function titleStart(){// タイトル画面 var scene = gameManager.createTitleScene(); core.replaceScene(scene); core.pause(); scene.on(enchant.Event.TOUCH_START, function(){gameStart();}); } //========== // EnchantJS enchant(); var gameManager; var core; var scene; window.onload = function(){ gameManager = new common.GameManager(); core = gameManager.createCore(320, 480); core.preload(assets); core.onload = function(){titleStart();}; core.start(); }