zondag 20 december 2015

Stencyl / HaXe : Replace TileSet image dynamically ( levels ? )


Note: Blog Post is a quick proof-of-concept outline that was used to replace a tilesheet. It is not a 'use-everywhere'-scenario.

Assumption : there is only one TileSet made in Stencyl {(resources.get(0)}


// old => cast(Data.get().resources.get(0),Tileset).bitmapData=bitmapData;
cast(Data.get().resources.get(0),Tileset).pixels=bitmapData;
// make the rest (than flash) use the tilesheet construction
#if cpp
cast(Data.get().resources.get(0),Tileset).setupTilesheet();
//.bitmapData=bitmapData;
#end

Also you can use the nme.net.URLRequest together with the
nme.display.Loader  (loader.load(new URLRequest(theURL));)
in combination with the 
loaderinfo.content.somehtning.addeventlistener(event.complete,do_the_above_with_tileset_function);


var bit:Bitmap = new Bitmap();
bit.bitmapData = bitmapData;
g.drawImage(bitmapData,0,0,0);

//this.engine.g.canvas.graphics.drawImage(bit, 0,0,0);
/*
var url:String="https://dl.dropboxusercontent.com/u/107982821/test.png";
var loader:Loader = new Loader();
   var urlRequest:URLRequest = new URLRequest(url);
   if(urlRequest != null)loader.load(urlRequest);    
   var b:Bitmap = new Bitmap();
   if (loader.content != null) {
   b = cast(loader.content,Bitmap);
  
     }
     */

  
     /*
g.fillColor=330;
//this.engine.g.canvas.graphics.fillRect(0,0,50,530);
if( b != null){
g.drawImage(b.bitmapData,0,0,0);
}else{
   g.fillRect(0,0,50,50);
}
*/
/*
//actorOfType.originMap.set("1"), new B2Vec2());
var i:Array<Int> = new Array<Int>();
i.push(100);
var ba:BitmapAnimation = new BitmapAnimation(b.bitmapData,1,i,false,null);
actorOfType.addAnimation("1",ba);
//var picLoader = new Loader();
//var spritePic = picLoader.load(new URLRequest("https://dl.dropboxusercontent.com/u/107982821/test.png"));

*/

Geen opmerkingen:

Een reactie posten