《Sprite1》.intersect(《Sprite2》);
Sprite1にSprite2が接触したかどうかを調べます。接触している場合はtrue、そうでない場合はfalseが返されます。「接触している」というのは、2つのSpriteの領域の一部が重なっているかどうかでチェックされます。《Sprite1》.within(《Sprite2》, 距離 );
これはSprite1とSprite2の中心地点の距離が第2引数の値より近づいたかどうかをチェックするものです。これもグラフィックとは関係なく、2つのSpriteの中心位置の距離を調べ、それによって衝突したかどうかを判断します。※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
enchant(); var char_arr = new Array(); window.onload = function(){ var game = new Game(1000, 700); game.preload("character.png"); game.fps = 20; game.onload = function(){ for(var i = 0;i < 10;i++){ var char1 = new Sprite(100, 100); char1.image = game.assets["character.png"]; char1.x = Math.floor(Math.random() * 900); char1.y = Math.floor(Math.random() * 600); char1.dx = Math.floor(Math.random() * 10); char1.dy = Math.floor(Math.random() * 10); char1.flg = true; char1.addEventListener(enchant.Event.ENTER_FRAME, function(){ if (this.flg){ this.frame = this.age % 2; } this.x += this.dx; this.y += this.dy; if (this.x < 0 || this.x > game.width - 100){ this.dx *= -1; } if (this.y < 0 || this.y > game.height - 100){ this.dy *= -1; } for(var i = 0;i < 10;i++){ if (this != char_arr[i]){ if (this.within(char_arr[i],50)){ this.dx = 0; this.dy = 0; this.flg = false; } } } }); game.rootScene.addChild(char1); char_arr[i] = char1; } game.rootScene.backgroundColor = "#ffaaaa"; } game.start(); };
<< 前へ | 次へ >> |