Wednesday, June 30, 2010

Basic 3d using ActionScript 3

With the come of AS3, a new axis Z is introduced, allowing the users to work in 3d world. The following example lets you rotate the picture using the X, Z and Y axises:






The code is pretty simple, just change the value of an object's rotation:

object.rotationX=10
object.rotationZ=20
object.rotationY=30

If you want to keep an object spinning, use ENTER_FRAME events:

stage.addEventListener(Event.ENTER_FRAME, spinner);

function spinner(Event){
object.rotationX++
}

The following example demonstrates rotation of an object using different axises:


What happens when you move (not rotate!) an object using one axis:



Although Flash supports 3d features like this, there are still some issues. Take a look at the next example:



Something about that animation isn't right. The objects in a real 3d world would collide with each other and some parts of one object would go through another one in a situation like this, however this does not happen in flash. Every object is in a "separate 3d world" and does not interact with other objects.

1 comment:

sidd said...

very nice tutorial .Keep it up (already faved your site)

Post a Comment