下記のURLよりもぐら叩きゲームをダウンロードして加工しています
http://code.9leap.net/codes/show/164339
原因が解らないのですが
終了時にTIMEが0.98とか0.97になります。
自分で色々考えて、if (timeLabel.time <= 0) の部分で
強制的にtimeLabel.time=0;とすれば厳密ではないけど0になると思い
設定しましたが変わらずでした。
if (timeLabel.time <= -0.1)にすると今度は終了時のTIMEが-0.03となりました。
きっちりゼロにすることはかのうでしょうか?
以下抜粋ソースコード
Javascript
1 //タイムラベルの生成 2 timeLabel = new TimeLabel(5, 25, "countdown"); 3 timeLabel.time = 5; 4 timeLabel.onenterframe = function() { 5 if (timeLabel.time <= 0) { 6 timeLabel.time=0; 7 game.end(); 8 }
以下全ソースコード
javascript
1enchant(); 2 3//オブジェクト 4var game; 5var scoreLabel; 6var timeLabel; 7var mogura = new Array(9); 8 9//乱数の取得 10function rand(num) { 11 return Math.floor(Math.random() * num); 12} 13 14//もぐらクラス 15Mogura = Class.create(Sprite, { 16 //初期化 17 initialize: function(x, y) { 18 Sprite.call(this, 80, 80); 19 this.image = game.assets["mogura.png"]; 20 this.x = x; 21 this.y = y; 22 this.status = -rand(200); 23 }, 24 25 //画面更新のたびに実行する処理 26 onenterframe: function() { 27 //フレームの変更 28 this.status++; 29 if (this.status < 0) { 30 this.frame = 0; 31 } else if (this.status == 0) { 32 this.frame = 1; 33 } else if (this.status == 30) { 34 this.status = -rand(200); 35 } 36 }, 37 38 //タッチした時の処理 39 ontouchend: function() { 40 if (this.frame == 1) { 41 this.frame = 2; 42 this.status = 0; 43 scoreLabel.score += 100; 44 } 45 } 46}); 47 48//メインプログラム 49window.onload = function() { 50 //Gameオブジェクトの生成 51 game = new Game(320, 320); 52 game.rootScene.backgroundColor = "rgb(144,198,116)"; 53 54 //画像の読み込み 55 game.preload("mogura.png"); 56 57 //ゲームの前処理完了時に呼ばれる 58 game.onload = function() { 59 //もぐらの生成 60 for (var i = 0; i < 9; i++) { 61 mogura[i] = new Mogura(20 + i % 3 * 100, 50 + Math.floor(i / 3) * 80); 62 game.rootScene.addChild(mogura[i]); 63 } 64 65 //スコアラベルの生成 66 scoreLabel = new ScoreLabel(5, 5); 67 scoreLabel.score = 0; 68 game.rootScene.addChild(scoreLabel); 69 70 //タイムラベルの生成 71 timeLabel = new TimeLabel(5, 25, "countdown"); 72 timeLabel.time = 5; 73 timeLabel.onenterframe = function() { 74 if (timeLabel.time <= 0) { 75 timeLabel.time=0; 76 game.end(); 77 } 78 } 79 game.rootScene.addChild(timeLabel); 80 } 81 82 //ゲームの開始 83 game.start(); 84}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。