[haXe] [Q] More BitmapData Mayhem....

Guntur N. Sarwohadi gsarwohadi at gmail.com
Fri Jul 6 09:55:37 CEST 2007


Hi Michael,

The problem is copyTexture is called before onLoad event handler. So
practically _bitmapData is copied to _offscreenBitmapData, before it draws
texture.gif from _loader. One way to solve this is to call copyTexture right
after _bitmapData.draw() in onLoad.

Hope that helps.

Guntur

On 7/6/07, Michael Norton <mnorton at wecare.net> wrote:
>
>
> hi,
>
> I am sluggishly coming up to speed on how HaXe handles BitmapData. I
> have the following scenario where I call a Loader object _loader to
> load my GIF file. This works.
> I load the contents of _loader into a BitmapData object _bitmapData.
>
> I now want to carve up the contents (sprites and textures in the gif)
> in _bitmapData into different BitmapData objects.
>
> I can't seem to be able to grab the contents of _bitmapData using my
> method, copyTexture().
> I create a BitmapData object called ifloor (floor texture) and
> initialize it funky green so I can see my pixel copying working. When
> I copy pixels from _bitmapData I get all black pixels displayed and
> no pixel content from _bitmapData. <- Undesired result.
>
> The desired final effect is to see the pixels of _bitmapData clip
> rect (0,0,194,64) displayed in the upper left corner (0,0,194,64) of
> the _offscreenBitmapData object (yellow). Not happening. I am seeing
> a big black strip. In all intents and purposes -the loader appears to
> be working.
>
> What am I forgetting to initialize here?
>
> thanks
>
> Mike
>
> import flash.display.MovieClip;
> import flash.display.BitmapData;
> import flash.display.Bitmap;
> import flash.net.URLRequest;
> import flash.events.Event;
> import flash.events.IOErrorEvent;
> import flash.geom.Matrix;
> import flash.display.Loader;
> import flash.display.StageAlign;
> //import flash.display.StageScaleMode;
> import flash.geom.Rectangle;
> import flash.geom.Point;
>
>
> class BRender {
> private var _bitmapData:BitmapData;
> private var _bitmap:Bitmap;
> private var _loader:Loader;
> private var _url:String;
> private var _offscreenBitmap:Bitmap;
> private var _offscreenBitmapData:BitmapData;
> public function new() {
> var bitmapData = new BitmapData(200,200, false, 0x000000);
> var bitmap:Bitmap = new Bitmap(bitmapData);
> _offscreenBitmapData = new BitmapData(320, 240, false, 0xffcc00);
> _offscreenBitmap = new Bitmap(_offscreenBitmapData);
> _bitmapData = bitmapData;
> _bitmap = new Bitmap(_bitmapData);
> flash.Lib.current.addChild(_bitmap);
> flash.Lib.current.addChild(_offscreenBitmap);
> _loader = new Loader();
> _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
> _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> ioErrorHandler);
> }
>
> // event handler for Loader
> public function onLoad(event:Event):Void {
>    _bitmapData.draw(_loader, new Matrix());
> }
>
> // ioError handler for Loader
> private function ioErrorHandler(event:IOErrorEvent):Void {
> trace("FS err: " + _url);
>      }
>
>      // load a texture from a file (Loader)
>      private function loadTexture( url:String ) {
>       _url = url;
>     var request:URLRequest = new URLRequest(_url);
> _loader.load(request);
>      }
>
>      // copy info
>      public function copyTexture():Void {
>        var dstPt = new Point(0,0);
>        var srcRect = new Rectangle(0,0,192,64);
>        var ifloor = new BitmapData(192, 64, false, 0x00cc00); //
> 0x00cc00 - Bright Green
>        ifloor.copyPixels( _bitmapData, srcRect, dstPt); // <- only
> get black strip..
>        _offscreenBitmapData.copyPixels( ifloor, srcRect, dstPt);
>      }
>
>      public function update_offscreenBitmapData() {
>       _offscreenBitmapData.draw(_bitmapData);
>       trace("update_offscreenBitmapData : done");
>      }
>
> public static function main(){
> var br = new BRender();
> br.loadTexture("textures.gif");
>
> br.copyTexture();
>
> }
>
>
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/haxe/attachments/20070706/71d42629/attachment.htm


More information about the Haxe mailing list