zondag 20 december 2015

Stencyl / HaXe : Changing Background using an Actor



Changing Background using Actor

Put an Actor on the scene (with invisible pixels)
Put it on the scene on the 0 layer
Put the tiles on the 1 layer
Put the Player on either layer 2 or layer 1

The background actor needs two animations. The first is the invisible one to start with.
The second is the name that is ‘animation_name2’ refered later in the code.
This animation will be overriden by the code

for each [actor of type] [Select the Background Actor]
Code-block:
  var bitmapData = new BitmapData(1024,1024,false, 0x000000);
  // load the image into the bitmapData or use the following code:


   var i:Int=0;
   var j:Int=0;
  var rc:Int=0;
  var gc:Int=0;
   var bc:Int=0;
  for(i in 1 ... 1020){
      for(j in 1 ... 1020){
   var pixel=i;
   rc=pixel;
   gc=pixel+rc;
   bc=pixel+gc;
  
  bitmapData.setPixel(i,j,(rc<<16|gc<<8|bc));
   }
}

var iti:Array<Int> = new Array<Int>();
iti.push(100); // animation time
var ba:BitmapAnimation = new BitmapAnimation(bitmapData,1,iti,true,null);
// animation_name2 must exist (as a second animation on the Actor)
actorOfType.addAnimation("animation_name2",ba);
actorOfType.originMap.set("animation_name2", new B2Vec2(bitmapData.width/2,bitmapData.height/2));

// --- EOP

Add Event: Custom : Import code:

// Change bitmap
import nme.display.BitmapData;
import nme.display.Bitmap; // when converting data
import com.stencyl.Data;

// URL loading
import nme.display.Loader;
import nme.net.URLRequest;
// Changing the Actor image
import box2D.common.math.B2Vec2;
import com.stencyl.graphics.BitmapAnimation;
// --



Geen opmerkingen:

Een reactie posten