3d Sprites

David Jones
@david3jones
avatar-davidejones

A sprite in alternativa3d terms is a 2d image that will face you as you move around in 3d space. There are quite a few examples of this in the alternativa3d demos but i thought i would give a quick example of how to acheive this.

Open up flash and create a new document and create a actionscript frame.

import alternativa.types.*;
import alternativa.engine3d.core.*;
import alternativa.engine3d.display.*;
import alternativa.engine3d.materials.*;
import alternativa.engine3d.primitives.*;
//this will take our bitmap and use it for texture
var tex:Texture = new Texture(new logo(0,0));
//now we need to create a sprite texture material to contain the texture
var stm:SpriteTextureMaterial = new SpriteTextureMaterial(tex);
//lets create the 3d sprite
var s3d:Sprite3D = new Sprite3D("s");
//now all we need to do is tell the sprite what material to use
s3d.material = stm;
//now lets do the rest of the work to setu the camera and scene
var scene:Scene3D = new Scene3D;
scene.root = new Object3D;
scene.root.addChild (s3d);
var view:View = new View;
view.camera = new Camera3D;
scene.root.addChild (view.camera);
view.width = view.height = 200;
addChild (view);
scene.calculate();
addEventListener(Event.ENTER_FRAME, onent);
function onent(e:Event):void {
    	scene.calculate ();
}

In order for this code to work you will need to add an image to your flash library and export it for actionscript with a base class of flash.display.BitmapData. In this case i called it logo which is why i have the following line

var tex:Texture = new Texture(new logo(0,0));

If you are also having problems seeing the sprite you may need to adjust its position, you can do so by using the following with different values

s3d.z = 200;

Comments

  • avatar-meghs
    # meghs

    Is this code is working…. because I try it using alternativa 3D 8 swc getting

    error Type was not found or was not a compile-time constant: Scene3D.

    help required.

  • avatar-davidejones
    # davidejones

    This works only with version 7, the version 8 system is quite different and supports gpu and stage3d etc.

    Checkout examples for version 8!

Comments are currently closed