I am trying to get the four corners of my object. To test out whether its accurate enough. use a method to trace a message when my mouse passes the objects bottom, left, right, or top. when the object is positioned at coord 0,0. it works perfect. but when I reposition it. It becomes off and I have no idea why. here is my code.
in my class, there is a loop that has 2 methods.updateArea(). and checkball. update area constant give update to where the object is. my display object forcus point is at the top left on my Flash Stage. so I use the full width and height. again. it works fine at coordinate 0,0 and when I move it, it doesnt.
package com.objects {
import flash.display.Sprite;
import flash.events.*;
import flash.display.Stage;
import flash.geom.Rectangle;
public class Brick extends Sprite {
public var Points = 100;
public var bWidth:Number = 50;
public var bHeight:Number = 20;
private var left:Number;
private var right:Number;
private var top:Number;
private var bottom:Number;
public var ball:Ball;
private var lastDistance:Number;
public var hit:Boolean;
public function Brick():void
{
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
updateArea();
checkBall();
}
private function updateArea():void {
left = x;
right = x + bWidth;
top = y;
bottom = y + bHeight;
}
private function checkBall():void
{
if(mouseY < bottom)
{
trace("Works!");
}
}
public function getBall(ball:Ball):void
{
this.ball = ball;
}
public function xDir():Number
{
if ((ball.xDir * ball.xspeed) < 0)
{
return(-1);
}
else if ((ball.xDir * ball.xspeed) > 0)
{
return (1);
}
return 0;
}
public function yDir():Number
{
if (ball.yspeed < 0)
{
return(-1);
}
else if (ball.yspeed > 0)
{
return (-1);
}
return 0;
}
}
}