I have two Movie clips that are added to the stage via AS3 using Flash Develop, one movie clip named playerHook
and the other fisherman
. Both are added to the stage in my main constructor function like so:
fisherman = new mcFisherman;
stage.addChild(fisherman);
fisherman.x = (stage.stageWidth / 2) + 250;
fisherman.y = (stage.stageHeight / 2) - 100;
I have a separate function called playerHookLine();
which is called by my main event enter frame gameloop.
This function connects two movie clips with a line and is supposed to act like a fishing pole line. Which It does very nicely.
The problem I am having is when I start to play the game my hook line doesn't register the HitTestObject
like my playerHook
movie clip does.
I have managed to tweak the code a little bit and it does start to register but then none of the points where the line is supposed to be connected are correct, its all over the place. Here is the code for the function:
private function playerHookLine():void
{
graphics.clear();
graphics.lineStyle(1, 0, 1);
graphics.moveTo(fisherman.x, fisherman.y);
graphics.curveTo(playerHook.x, playerHook.y, mouseX, mouseY);
}
When I change the code to this:
private function playerHookLine():void
{
playerHook.graphics.clear();
playerHook.graphics.lineStyle(1, 0, 1);
playerHook.graphics.moveTo(fisherman.x, fisherman.y);
playerHook.graphics.curveTo(playerHook.x, playerHook.y, mouseX, mouseY);
}
then it registers the hitTest along with the hook but the line is no longer in the correct position. What am I doing wrong, how should I correctly use the Graphics API code? I want the line and the PlayerHook to both hitTest with the enemy on screen but I also want the line to still be connected to the fisherman and the playerHook.
Lastly, my playerHook is controlled by the mouse. So it moves wherever the mouse moves.
Here is what I have so far:
private function playerHookLine():void
{
var playerHookGlobalPos:Point = playerHook.localToGlobal(new Point());
var fishermanGlobalPos:Point = fisherman.localToGlobal(new Point());
playerHook.graphics.clear();
playerHook.graphics.lineStyle(1, 0, 1);
playerHook.graphics.moveTo(fisherman.x, fisherman.y);
playerHook.graphics.curveTo(playerHookGlobalPos.x, playerHookGlobalPos.y, mouseX, mouseY);
}
but it doesnt work