Skip to content

C3D 02 Creating a Scene

robsilv edited this page Apr 12, 2013 · 7 revisions

First of all, let's create the basic CadetScene.

Update your CadetHello3D with the following code:

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import cadet.core.CadetScene;
	
	import cadet3D.components.renderers.Renderer3D;
	
	[SWF( width="700", height="400", backgroundColor="0x002135", frameRate="60" )]
	public class CadetHello3D extends Sprite
	{
		private var cadetScene:CadetScene;
		
		public function CadetHello3D()
		{
			cadetScene = new CadetScene();
			
			var renderer:Renderer3D = new Renderer3D();
			renderer.viewportWidth = stage.stageWidth;
			renderer.viewportHeight = stage.stageHeight;
			cadetScene.children.addItem(renderer);
			renderer.enable(this);
			
			addEventListener( Event.ENTER_FRAME, enterFrameHandler );
		}
		
		private function enterFrameHandler( event:Event ):void
		{
			cadetScene.step();
		}
	}
}

If you compare this code with the equivalent 2D tutorial, you'll see that the code is identical to the 2D version in all important respects, apart from the fact we're adding a Renderer3D as opposed to a Renderer2D.

Due to the plug-and-play nature of the CadetEngine, all you have to do is add your Renderer to the CadetScene and the rest is taken care of for you. Currently there's nothing in our scene, so if you build and run you won't see much, but we'll start adding stuff in the next tutorial.

< Previous | Next >