Hi
I’m designing a maze type of game. The character can only walk on a line. I’m trying to test if the character is on the line (land). If he isn’t on the line, he isn’t supposed to move (i.e. disable the arrows that control him).
The easiest way I thought to test this, is to test the color the character is on. (The line is “66CC00” and the rest is “999999”).
My code:
var land:Boolean = false;
var bmp:BitmapData = new BitmapData(this.width, this.height, false);
bmp.draw(this);
var pColor:Number = bmp.getPixel(character1_mc.x, character1_mc.y);
var hexColor:String;
stage.addEventListener(Event.ENTER_FRAME, color);
function color(event:Event):void
{
hexColor = pColor.toString(16).toUpperCase();
while(hexColor.length < 6){
hexColor = "0" + hexColor;
}
if(hexColor == "66CC00")
{
land = true;
}
else if(hexColor == "999999")
{
land = false;
}
}
My character stands on “66CC00” in the beginning, so that he can start moving. When I trace hexColor it stays on “66CC00” even though my character moves onto “999999”.
What am I doing wrong?