shessocrafty
09-08-2008, 04:31 AM
Ok so I have configured a target mouse... and I have a cannon that I thought was ok... I was happy to have it move and then realized its moving in the exact opposite direction of the mouse is moving... Then I figured out that there was math involved in this and needless to say after lots of scary hours I'm kinda toasted... here is my code any help would be greatly appreciated! the mouse x and mouse y were initially both at zero then I figured I should change them to the coordinates of the actual cannon and that didn't work... I know its probably something stupidly ridiculous but I really can't figure it out!
var cursor:MovieClip;
function initializeGame():void
{
cursor = new Crosshair();
addChild(cursor);
cursor.enabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCrosshair);
}
stage.addEventListener( MouseEvent.MOUSE_MOVE, mouseInHandler );
function mouseInHandler( args : MouseEvent ) : void
{
if ( ( stage.mouseX >420) && ( stage.mouseY >97) &&
( stage.mouseX < 550 ) && ( stage.mouseY < 400 ) )
{
var angle = Math.atan2( ( stage.mouseY+280), stage.mouseX );
Cannon_mc.rotation = angle * ( 180 / Math.PI );
}
}
function dragCrosshair(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}
initializeGame();
var cursor:MovieClip;
function initializeGame():void
{
cursor = new Crosshair();
addChild(cursor);
cursor.enabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCrosshair);
}
stage.addEventListener( MouseEvent.MOUSE_MOVE, mouseInHandler );
function mouseInHandler( args : MouseEvent ) : void
{
if ( ( stage.mouseX >420) && ( stage.mouseY >97) &&
( stage.mouseX < 550 ) && ( stage.mouseY < 400 ) )
{
var angle = Math.atan2( ( stage.mouseY+280), stage.mouseX );
Cannon_mc.rotation = angle * ( 180 / Math.PI );
}
}
function dragCrosshair(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}
initializeGame();