《Scene》.removeChild(《Sprite》);
Sceneは、game.rootSceneを直接指定してもいいのですが、thisの「parentNode」を参照することで、thisが組み込まれているオブジェクトを得ることができます。ここからremoveChildでthisを削除すればいいわけです。※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
enchant(); var char_arr = new Array(new Array(),new Array(),new Array()); var enemy_arr = new Array(); window.onload = function(){ var game = new Game(1000, 700); game.preload("character.png", "enemy.png"); game.fps = 20; game.rootScene.backgroundColor = "#ffaaaa"; game.onload = function(){ // 敵キャラ for(var i = 0;i < 3;i++){ var enemy = new Sprite(50, 50); enemy.image = game.assets["enemy.png"]; enemy.x = game.width - 50; enemy.y = game.height - 50; enemy.counter = Math.floor(Math.random() * 100) + 100; enemy.dx = Math.floor(Math.random() * 10); enemy.dy = Math.floor(Math.random() * 10); enemy.addEventListener(enchant.Event.ENTER_FRAME, function(){ this.counter--; if (this.counter <= 0){ this.counter = Math.floor(Math.random() * 100) + 100; this.dx = Math.floor(Math.random() * 10); this.dy = Math.floor(Math.random() * 10); } this.x += this.dx; this.y += this.dy; if (this.x < 0 || this.x > game.width - 50){ this.dx *= -1; } if (this.y < 0 || this.y > game.height - 50){ this.dy *= -1; } }); game.rootScene.addChild(enemy); enemy_arr[i] = enemy; } //操作するキャラ for(var i = 0;i < 3;i++){ for(var j = 0;j < 3;j++){ var char1 = new Sprite(100, 100); char1.image = game.assets["character.png"]; char1.x = i * 100; char1.y = j * 100; char1.addEventListener(enchant.Event.ENTER_FRAME, function(){ this.frame = this.age % 2; if (game.input.up){ this.moveBy(0, -5); } if (game.input.down){ this.moveBy(0, 5); } if (game.input.left){ this.moveBy(-5, 0); } if (game.input.right){ this.moveBy(5, 0); } for(var i = 0;i < 3;i++){ if (this.within(enemy_arr[i],50)){ var parent = this.parentNode; parent.removeChild(this); if (parent.childNodes.length == 3){ game.stop(); alert("GAME OVER"); } } } }); game.rootScene.addChild(char1); char_arr[i][j] = char1; } } }; game.start(); };
<< 前へ |