Hello, i’ve played quite a bit with AS3 lately, but i got stuck for over a day in 1 spot, i would appreciate some help.
This is my main file:
public class Game extends MovieClip
{
public function Game()
{
var player:Player= new Player();
player.getPlayer(stage);
this.stage.addChild(player);
stage.addEventListener(KeyboardEvent.KEY_DOWN, player.keyPressedDown);
var apple:FructCreator = new FructCreator();
apple.makeFruct(1,100,100,1);
apple.go();
addEventListener(Event.ENTER_FRAME,checkcol);
function checkcol(event:Event)
{
if(apple.hitTestObject(player))
{
trace("Colizion !!");
}
}
}
}
and this is makeFruit method
public function makeFruct( $type:int,
$initX:Number, $initY:Number,
$speed:Number):void
{
fruct = this.createFruct($type);
fruct.buildFruct();
fruct.setSpeed($speed);
fruct.initXY($initX,$initY);
addChild(fruct);
}
like this, i get collision message, but, i cannot see the apple.
I tried (the red code its added):
public function makeFruct( $type:int,[COLOR=Red] $target:Stage,[/COLOR]
$initX:Number, $initY:Number,
$speed:Number):void
{
fruct = this.createFruct($type)
fruct.buildFruct()
fruct.setSpeed($speed)
fruct.initXY($initX,$initY)
[COLOR=Red]$target.[/COLOR]addChild(fruct)
}
And after i added stage in my main class
apple.makeFruct(1,this.stage,100,100,1);
now, i can see the apple, but i don’t detect collision anymore.
I guess its either something about “stage”, or something wrong with my use of “addChild”.
Thanks a lot for reading this, i would really appreciate any feedback.
I can provide the rest of code, but works nicely.