Hello, I’m trying to detect which pixels are opaque and which are transparent in a bitmap .png image used as a texture on a plane in away3d4.x without any luck.
I’m trying to make a game with a 3d map where you click on a country and it changes color.
In away3d3.6 I just applied a movie clip to a plane with MovieMaterial, but since it’s not available in 4.x I am trying to click just the opaque part of a .png image
and it will select it for my action script code.
Here’s the code I used in a class for the 3d map in away3d 3.6:
var THRESHOLD:Number = 0;
var scotsBitmapData:BitmapData = new Scots(205,229);
var scots:Bitmap = new Bitmap(scotsBitmapData);
var scotsSpt:Sprite = new Sprite;
var scotsTestGlobal:Boolean;
scots.x = 566;
scots.y = 468;
scotsBitmapData = scots.bitmapData;
scotsSpt.addChild(scots);
ireland.addChild(scotsSpt);
ireland.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
var pixel:uint = scotsBitmapData.getPixel32(mouseX-scots.x, mouseY-scots.y);
scotsTestGlobal = buttonMode = ((pixel >>>24) > THRESHOLD);
if(e.target == scotsSpt){
if(scotsTestGlobal){
useHandCursor = false;
countryClicked = “scots”;
}
This code was for the movie clip that I added to the plane in away3d3.6. In the new 4.x game I set texture.alphaBlending = true; so the .png would be transparent and added a MouseEvent3D to the plane:
_plane2.addEventListener(MouseEvent3D.MOUSE_MOVE, _OnMouseMove);
In the _OnMouseMove method I have this:
private function _OnMouseMove(ev : MouseEvent3D) : void
{
var pixel:uint = bitmapData.getPixel32(mouseX, mouseY);
testGlobal = buttonMode = ((pixel >>>24) > THRESHOLD);
if (!testGlobal){
thisText(mouseX,mouseY);
}
}
however this doesn’t work. I get mouseX and mouseY readings for when the mouse is over the transparent as well as opaque parts.
Anyone know how I could do this?
Anyone know how I could reference the bitmap texture material on the plane so I could test which parts are opaque and transparent using code like that above?