new target creation problem

10 replies to this topic
Posted 1+ years ago #1
Jesse

I have a problem. I am trying to create a monkey target that will work with stage3D. for those that don't know Stage3D is a flash hardware accelerated graphics Api. I am implementing hardware 2D accelerated graphics to replace the slow flash graphics. I got pretty much everything in place and working. its' very limited as it just works with sprites. A little demo to show that it's working:

http://www.hexobot.com/stage3D/MonkeyGame.html

it should work pretty good on handheld devices although I don't know. I haven't tested it.

it's working but not usable as a normal monkey target. what is happening is that the graphics need to be requested and then when the graphics is available a trigger and a function is called. The problem is the Oncreate is done processing before the graphics object is available. so I can not create any graphics while on the onCreate. I have to do a check while on Update and see if the graphics object is ready and then start to load all of the assets and object creation. which is not ideal. I am new to flash programming so I don't know if there is a way I can get the graphics object to be created and available before the On create is called?

anybody has any idea how I can resolve that?

I am thinking that maybe I can have a loop check until the graphics object is loaded and then continue to OnCreate. But I don't know.

any Ideas?

 
Posted 1+ years ago #2
AdamRedwoods

I am new with flash programming so I don't know if there is a way I can get the graphics object to be created and available before the On create is called?

not really. you are doing it correctly. I tried this and i had a problem with the frame rate not being set, so even if I were to create a program lock until the context was ready, it wouldn't execute.

For miniB3D Html5 and Stage3D (inprogress) I had to incorporate a ContextReady/AssetsLoaded check.

....But since you are creating a new TARGET, MonkeyV68 allows you to create your own GameDelegate, so you can modify the native .as file under your NEW target (under the target folder) and modify StartGame() or Run() to check/wait for the Stage3D context to be created. I may be a little off since I'm winging the answer, but poke around and you'll find the right entry point to check for the context.

 
Posted 1+ years ago #3
Jesse

Thanks Adam!

I didn't want to go into v68 yet but I guess I will now.

For miniB3D Html5 and Stage3D (inprogress)

I guess you are going the MinizB3D direction with it right?

 
Posted 1+ years ago #4
Jesse

well, I tried by modifying the delegate class but was unsuccessful at at getting results.

I need to know what module adds and removes triggers for Oncreate OnRender and OnUpdate etc? I looked but there are too many classes to go one by one analyze and understand. I am guessing thats how it's done in order for the events to occur in a certain order. I am thinking I can add a dummy method that would run until the graphics object is created. it's probably not possible and probably a dumb idea but I have exhausted all my option. any help is appreciated.

I will keep pounding away.

 
Posted 1+ years ago #5
Tibit

In the new target system you have the "delegate" with all those On methods plus a couple for OnTouch,OnKey. If you are after creating a new Flash target, I'd advice you copy the current flash target folder.

I haven't created a target yet, but that's where I'd start at least! :)

 
Posted 1+ years ago #6
Jesse

I have duplicated mojo and the flash target and that's how I am working. I did mention that I modified the delegate class on a previous post but still no luck. as I see it, the delegate method are that just methods but I need to know if there is something that assign them to triggers and active threads.

Thanks.

 
Posted 1+ years ago #7
AdamRedwoods

mojo/app.monkey examine that file for what is going on with the delegate.

 
Posted 1+ years ago #8
Jesse

I have an idea the entry point file is the MonkeyGame.as Template. I think I can set it up from there. before it adds any of the game events. Will try.

 
Posted 1+ years ago #9
Jesse

I have made the modification to the "MonkeyGame.as in the Templates. and everything works good until I need to remove an event to continue on to add the game event.

I add two events to the event listener the first event is to create the graphics object and the second event checks if the graphics object was crated. once the graphics object is crated the second event listener, the one that checks to see if the graphics object was created is supposed to be removed from the event stack. but for some reason it's not and it goes into a continuous loop.

does anyone know why it never removes event listener that checks for graphics object creation?

this is what I did:

package{
	import flash.display3D.*;


	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;

	[SWF(width="800",height="600")]
	public class MonkeyGame extends Sprite{
	
		protected var _stage3D:Stage3D;
		protected var _context3D:Context3D;
		protected var _stage:Stage;
		
		internal var vertexBuffer:VertexBuffer3D;
		internal var indexBuffer:IndexBuffer3D;
		internal var _modelViewMatrix : Matrix3D;
		
		public function MonkeyGame(){
			if (stage) 
				Request3DObject();
			else
				addEventListener(Event.ADDED_TO_STAGE,Request3DObject);
		
			addEventListener(Event.ENTER_FRAME,ReadyGraphics);
		}
		
		private function Request3DObject( e:Event=null ):void{
			removeEventListener(Event.ADDED_TO_STAGE, Request3DObject);
			_stage = stage;
			_stage.quality = StageQuality.LOW;
			_stage.align = StageAlign.TOP_LEFT;
			_stage.scaleMode = StageScaleMode.NO_SCALE;
			// Init stage3D 
			var stage3D:Stage3D = stage.stage3Ds[0];
			_stage3D = stage3D;			
			stage3D.addEventListener(Event.CONTEXT3D_CREATE, Int3D);        
			stage3D.requestContext3D(); 
		}
		
		private function Int3D(event:Event=null): void
		{
			var stage3D:Stage3D = event.currentTarget as Stage3D;
			_context3D = stage3D.context3D;
			_context3D.configureBackBuffer(stage.stageWidth, stage.stageHeight, 2); 
			// Create a vertexBuffer
			vertexBuffer = _context3D.createVertexBuffer(4,3);
				
			// Put some vertices into the buffer, 
			// and upload it to our GPU.
			var v:Vector.<Number> = new Vector.<Number>();
			v.push(-0.5,-0.5, 0, 0.5, -0.5, 0, -0.5, 0.5, 0, 0.5, 0.5, 0 );
			vertexBuffer.uploadFromVector(v,0, 4);
					
			// Create an indexBuffer
			indexBuffer = _context3D.createIndexBuffer(6);
			
			// Upload the contents of the indexBuffer to our GPU
			var v2:Vector.<uint> = new Vector.<uint>
			v2.push(1, 0, 2, 2, 3, 1);
			indexBuffer.uploadFromVector(v2,0, 6);
			
			_modelViewMatrix = new Matrix3D();
			_modelViewMatrix.appendTranslation(-stage.stageWidth/2, -stage.stageHeight/2, 0);            
			_modelViewMatrix.appendScale(2.0/stage.stageWidth, -2.0/stage.stageHeight, 1);
		}
		
		private function ReadyGraphics(e:Event=null):void{
			if( _context3D!=null ){
				throw("crated graphics object....");
				removeEventListener(Event.ENTER_FRAME,ReadyGraphics);
				addEventListener(Event.ADDED_TO_STAGE,OnAddedToStage);
			}	
		}

		private function OnAddedToStage( e:Event=null ):void{
			throw("starting game");
			BBMonkeyGame.Main( this );
		}

	}
}
 
Posted 1+ years ago #10
GW_

I don't know AS3 very well, but is it possible to add it again with a null argument to clear it?

 
Posted 1+ years ago #11
Jesse

Thanks GW_, I didn't see your post until now. that wouldn't have worked. I got it fixed any way.

I guess I was over thinking.
I finally got smart and looked at the tutorial example of a game. it was like this:

package{
	import flash.display3D.*;


	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;

	[SWF(width="640",height="480")]
	public class MonkeyGame extends Sprite{
	
		public var _stage3D:Stage3D;
		internal var _context3D:Context3D;
		internal var _stage:Stage;
		
		internal var vertexBuffer:VertexBuffer3D;
		internal var indexBuffer:IndexBuffer3D;
		internal var _modelViewMatrix : Matrix3D;
		
		public function MonkeyGame(){
			if (stage) 
				Request3DObject();
			else
				addEventListener(Event.ADDED_TO_STAGE,Request3DObject);
		
		}
		
		private function Request3DObject( e:Event=null ):void{
			removeEventListener(Event.ADDED_TO_STAGE, Request3DObject);
			_stage = stage;
			_stage.quality = StageQuality.LOW;
			_stage.align = StageAlign.TOP_LEFT;
			_stage.scaleMode = StageScaleMode.NO_SCALE;
			// Init stage3D 
			var stage3D:Stage3D = stage.stage3Ds[0];
			_stage3D = stage3D;			
			stage3D.addEventListener(Event.CONTEXT3D_CREATE, Init3D);        
			stage3D.requestContext3D(); 
		}
		
		private function Init3D(event:Event=null): void
		{
			var stage3D:Stage3D = event.currentTarget as Stage3D;
			_context3D = stage3D.context3D;
			_context3D.configureBackBuffer(stage.stageWidth, stage.stageHeight, 2); 
			BBMonkeyGame.Main( this );
		}
				
	}
}