HardeKernNL
12-11-2011, 02:18 PM
Hi there,
My second question on this forum already!
For a school assignment I'm setting up a duckhunt game. I've got the cursor acting as a gun and random ducks fly into the screen. These ducks are movieclip who are clickable and are moving.
I made an eventhandler so the duck wil disappear. Here comes my problem...
When the duck flies into the screen I can click multiple times but nothing is happening. Once in a while the duck disappears and the trace() tells me the duck is clicked.
It just looks like I need to hit the duck at a specific area or so.
Any solutions? thanks in advance
code:
stage.addChild(sniper_mc);
sniper_mc.mouseEnabled = false;
var snelheidDuck:int = Math.random() * 10 + 5;
//Eventlisteners
sniper_mc.addEventListener(Event.ENTER_FRAME, sniperCursor);
duck_mc.addEventListener(Event.ENTER_FRAME, animatieHandler);
duck_mc.addEventListener(MouseEvent.MOUSE_DOWN, sniperHandler);
//Functions;
function sniperCursor(evt:Event)
{
sniper_mc.x = stage.mouseX;
sniper_mc.y = stage.mouseY;
}
function animatieHandler(evt:Event)
{
duck_mc.x += snelheidDuck;
if (duck_mc.x > 600)
{
duck_mc.x = -238;
duck_mc.y = Math.random() * 342;
snelheidDuck = Math.random() * 10 + 5;
}
}
function sniperHandler(evt:MouseEvent):void
{
trace("mouseklik")
duck_mc.x = -238;
duck_mc.y = Math.random() * 342;
snelheidDuck = Math.random() * 10 + 5;
}
Mouse.hide();
My second question on this forum already!
For a school assignment I'm setting up a duckhunt game. I've got the cursor acting as a gun and random ducks fly into the screen. These ducks are movieclip who are clickable and are moving.
I made an eventhandler so the duck wil disappear. Here comes my problem...
When the duck flies into the screen I can click multiple times but nothing is happening. Once in a while the duck disappears and the trace() tells me the duck is clicked.
It just looks like I need to hit the duck at a specific area or so.
Any solutions? thanks in advance
code:
stage.addChild(sniper_mc);
sniper_mc.mouseEnabled = false;
var snelheidDuck:int = Math.random() * 10 + 5;
//Eventlisteners
sniper_mc.addEventListener(Event.ENTER_FRAME, sniperCursor);
duck_mc.addEventListener(Event.ENTER_FRAME, animatieHandler);
duck_mc.addEventListener(MouseEvent.MOUSE_DOWN, sniperHandler);
//Functions;
function sniperCursor(evt:Event)
{
sniper_mc.x = stage.mouseX;
sniper_mc.y = stage.mouseY;
}
function animatieHandler(evt:Event)
{
duck_mc.x += snelheidDuck;
if (duck_mc.x > 600)
{
duck_mc.x = -238;
duck_mc.y = Math.random() * 342;
snelheidDuck = Math.random() * 10 + 5;
}
}
function sniperHandler(evt:MouseEvent):void
{
trace("mouseklik")
duck_mc.x = -238;
duck_mc.y = Math.random() * 342;
snelheidDuck = Math.random() * 10 + 5;
}
Mouse.hide();