Vote count:
0
Help me.. i'm making rpg for my school project and the code hitTestObject inside NPC01 class is not working.
Here's my code:
Game.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Game extends MovieClip{
var map:Map = new Map();
var player:Player = new Player();
var npc:NPC = new NPC();
public function Game(){
addChild(map);
addChild(npc);
addChild(player);
this.addEventListener(Event.ENTER_FRAME,loop);
}
private function loop():void {
npc.x = map.x;
npc.y = map.y;
}
}
}
NPC.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class NPC extends MovieClip {
var npc01:NPC01 = new NPC01();
public function NPC() {
// constructor code
addChild(npc01);
npc01.x = 20;
npc01.y = 0;
}
}
}
NPC01.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class NPC01 extends MovieClip {
var player:Player = new Player();
public function NPC01() {
// constructor code
this.addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
if(player.hitTestObject(npc)) { //npc is a movieclip inside NPC01
trace("HIT!!");
}
}
i got no error message. it just, whenever the player movieclip hits npc movieclip, the output doesn't show up..
i tried also to also to trackdown their position using:
trace( player.getBounds(stage) );
trace( npc.getBounds(stage) );
result:
(x=343, y=218, w=26, h=45)
(x=334, y=218, w=32, h=51)
it seems that they are colliding.
But when i write the hitTestObject code inside the Game.as under function loop, and the trace output show's up when the player hits npc.
i got no problem moving the charater 'player' around.
Sorry for my bad English.
asked 1 min ago
Action Script 3.0 HitTestObject Not Working?
Aucun commentaire:
Enregistrer un commentaire