Does anybody know how to use copyPixels to display a hover image when the mouse is over the original copied pixels? Using hitTest and bitmapData…
The only way I can get this code to copy the new image over the old is by setting the If statement to == false. The mouse isn’t working and I’m not sure how to affect just the pixels that had been originally copied. I specified the hitTest to be applied to the bitmapData of the loaded .png because I don’t know what else to do but then the hitTest would apply to anything copied from that tile sheet.
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.events.Event;
public class BitmapButton extends Sprite
{
private var _canvasBitmapData;
private var _canvasBitmap;
private var _artBitmapData;
private var _artBitmap;
private var _artLoader;
private var _buttonTile;
private var _buttonPlacement;
private var _hoverTile;
private var _hoverPlacement;
private var _mouseLocation;
public function BitmapButton()
{
_artLoader = new Loader();
_artLoader.load( new URLRequest( "tile-set.png" ));
_artLoader.contentLoaderInfo.addEventListener( Event.INIT, initButton, false, 0, true );
}
private function initButton( event:Event ):void
{
_canvasBitmapData = new BitmapData( 640, 480, true, 0 );
_canvasBitmap = new Bitmap( _canvasBitmapData );
_artBitmapData = Bitmap( _artLoader.content ).bitmapData;
_artBitmap = new Bitmap( _artBitmapData );
_buttonTile = new Rectangle ( 0, 0, 200, 100 );
_buttonPlacement = new Point( 80, 150 );
_canvasBitmapData.copyPixels( _artBitmapData, _buttonTile, _buttonPlacement );
addChild( _canvasBitmap );
_mouseLocation = new Point( mouseX, mouseY )
if(_artBitmapData.hitTest( _buttonPlacement, 0xFF, _mouseLocation ) == true )
{
_hoverTile = new Rectangle ( 0, 100, 200, 100 );
_hoverPlacement = new Point( 80, 150 );
_canvasBitmapData.copyPixels( _artBitmapData, _hoverTile, _hoverPlacement );
}
}
}
}
Any help or clues would be really appreciated. People use blitted characters in interactive ways so there got to be a way but I’ve been trying different things for hours and hours the computer keeps saying “no, no, no, nope, wrong, wrong again, no, not that, nope, no, no, no, no, not a chance, no way, no, no, no…” and on like that.