Timing Tutorial

To view this page ensure that Adobe Flash Player version 11.0.0 or greater is installed.


The program in this tutorial is essentially same as the Basic Lighting Tutorial. This time, however, instead of updating the scene on EnterFrame, we use a tick manager and update the scene everytime the timer ticks. Tick maneger also passes a Time Info object so that we can keep track of the time.

package
{
	import com.yogurt3d.Yogurt3D;
	import com.yogurt3d.core.events.Yogurt3DEvent;
	import com.yogurt3d.core.lights.Light;
	import com.yogurt3d.core.managers.tickmanager.TickManager;
	import com.yogurt3d.core.managers.tickmanager.TimeInfo;
	import com.yogurt3d.core.materials.MaterialDiffuseFill;
	import com.yogurt3d.core.materials.MaterialFill;
	import com.yogurt3d.core.objects.interfaces.ITickedObject;
	import com.yogurt3d.core.sceneobjects.SceneObject;
	import com.yogurt3d.presets.primitives.sceneobjects.BoxSceneObject;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Vector3D;
	
	[SWF(width="800", height="600", frameRate="120")] // initialize SWF with a fixed frame rate of 120 fps
	/* This time our class implemets ITickedObject interface. Hence, it has to 
	implement the updateWithTimeInfo(_timeInfo:TimeInfo) method */
	public class Y3D_TimingTest extends Sprite implements ITickedObject
	{
		
		public var box:BoxSceneObject;
		
		// constructor, same as in previous tutorials, initilizes the engine
		public function Y3D_TimingTest()
		{
			Yogurt3D.instance.addEventListener( Yogurt3DEvent.READY, onContextReady );
			Yogurt3D.instance.init( this.stage );
		}
		
		// initializes the scene with default setup, adds a box and a light
		public function onContextReady( _e:Event ):void{
			
			
			Yogurt3D.instance.defaultSetup( );
			
			Yogurt3D.instance.defaultScene.sceneColor = 0xFF0000;
			
			
			box = new BoxSceneObject();
			
			box.material = new MaterialDiffuseFill( 0x00FF00,1 );
			
			
			Yogurt3D.instance.defaultScene.addChild( box );
			
			
			Yogurt3D.instance.defaultCamera.transformation.position = new Vector3D( 0,0,-20 );
			
			Yogurt3D.instance.defaultCamera.transformation.lookAt( new Vector3D );
			
			
			var light:Light = new Light( Light.DIRECTIONAL_LIGHT );
			
			light.transformation.position = new Vector3D(-10,-10,-10);
			
			light.transformation.lookAt( new Vector3D );
			
			
			Yogurt3D.instance.defaultScene.addChild( light );
			
			// start rendering loop
			Yogurt3D.instance.startAutoUpdate();
			
			// register the Y3D_TimingTest object to the Tick Manager
			TickManager.registerObject( this );
		}
		
		// This method updates the scene according to the time info
		// Tick manager ticks at each frame
		// timeInfo holds 3 seperate time information
		// systemTime: 
		// objectTime: 
		// deltaTime: 
		public function updateWithTimeInfo(_timeInfo:TimeInfo):void{
			// rotate the box according to the objectTime info
			box.transformation.rotationY = _timeInfo.objectTime / 1000 * 60;
		}
		
	}
}


New Version with Stage3D

Yogurt3D v2.1

About Yogurt3D

Yogurt3D Game Engine is a state of the art Actionscript 3.0 library for developing 3D applications on Adobe Flash Platform. We claim it is possible to create in-browser 3D games without any plug-in installation. Its animation system, model formats, exporter plug-ins for modelling tools, scene hierarchy and scene management structure, and that it is developed with a game developer perspective, makes Yogurt3D a powerful tool for 3D game developers.

If you wish to target both casual and seasoned players with browser-based real-time 3D games on the web, Yogurt 3D Game Engine is the ultimate tool to choose.

About Yogurt Technologies

Yoğurt Technologies was founded in 1997 by a group of artists and computer engineers.

For 10 years the group worked as a new media agency producing technology for other companies.

In 2007, the decision to focus on its own products was taken as Yoğurt members foresaw that 3D would be the next big thing on the web. Thus, the company now produces 3D tools that will be available to anyone who wants to try a hand on 3D content.

Yogurt3D on Social Networks

Follow Us on Facebook, Twitter and FriendFeed.