Posts Tagged ‘ActionScript’

PBE Series: quickly displaying sprites via ActionScript

December 16th, 2009

Prerequisites:

There’s not much to say. We’ll just create an entity with a sprite render component – and position it in our scene.

//Create a new entity:
var myEntity:IEntity = PBE.allocateEntity();
myEntity.initialize("MyEntity");
 
//Render component:
var renderComp:SpriteRenderer = new SpriteRenderer(); 
 
renderComp.scene = PBE.getScene();
renderComp.fileName = "../assets/Images/platform.png";
renderComp.position = new Point(0, 0);
renderComp.rotation = 0.0;
 
//Add the component to the entity:
myEntity.addComponent( renderComp, "Render" );

That’s the comfortable thing when working with PushButton Engine! You don’t necessary need a spatial component or such, just to display graphics. In case you wonder what a spatial component is: they’ll be covered in the next PBE Series tutorial!

PBE Series: initializing your scene via ActionScript

December 11th, 2009

Prerequisite: use a current version of PushButton Engine.

This will be a short tutorial. It will show you how to intialize your PushButton Engine scene properly via ActionScript.
Let’s get started! Somewhere in your main class, paste in this code:

// Startup the engine:
PBE.startup(this);
 
//Create your scene view:
var sceneView:com.pblabs.rendering2D.ui.SceneView = new com.pblabs.rendering2D.ui.SceneView();
 
//And now initialize the scene:
PBE.initializeScene( sceneView, "Scene", null, Box2DManagerComponent );
 
//Now you're ready to load a level file like so:
LevelManager.instance.load("../assets/levelDescriptions.xml", 1);
 
//Or create your entites directly in code:
var myEntity:IEntity = PBE.allocateEntity();
myEntity.initialize("MyEntity");
//...go on with adding components to your entity as you like :)

A quick remark on the initializeScene: if you don’t want or need the Box2DManagerComponent, you can use the BasicSpatialManager2D:

PBE.initializeScene( sceneView, "Scene", null, BasicSpatialManager2D );

That was it! Easy eh?