Posts Tagged Stage3D

Tricks when starting using the Starling framework

I am working on my next game, well trying to. I am a bit lazy but I am fighting that. Anyway I came to a point where performance was an issue in the prototype, so I decided it was time to jump into the Starling Framework.

I have been wanting to try it for some time and I must say it was quite easy to port my existing code to it since it uses the same API than the Flash display list. But there are a lot of little things that are different. I’m am going to list a few gotchas, but first I think every one new to Starling should read Thibault Imbert book (which is free) about it. It is only 122 pages long and it took me about 20 mins to go through it. Also the wiki on the starling framework website is quite useful.

Starling; the walled garden

Here is the code you need to start Startling:

_starling = new Starling(Game, stage);
_starling.start();

Game being a class where you will control what will happen inside of Starling (also called the Root Class). Now you see my next game interface will use the normal Flash display list, but from it the user will be able to change stuff that happens on the graphics inside Starling. So I need a way to communicate with it, but there is no easy way to access the Game class… Here is the way I found:

_starling.addEventListener(Event.ROOT_CREATED, _onRootCreated);
private function _onRootCreated(event:Event):void {
	_starling.removeEventListener(Event.ROOT_CREATED, _onRootCreated);
	_game = Starling.current.stage.getChildAt(0) as Game;
	_game.init(_whateverData);
}

If you ask me this is a bit hackish, mostly the stage.getChildAt(0) but it works. I think you should just be able to access it using Starling.rootClass but that is just me I guess. I read somewhere that you could listen to the Event.CONTEXT3D_CREATE but that didn’t work in the latest version.

Little differences

So they wanted Starling to be similar to the display list but some little differences remained. The first one I noticed was that the rotation property on a DisplayObject is in radians instead of degrees. A bit annoying but not really a huge thing. Starling comes with a utility function to convert angles that you can find here: starling.utils.deg2rad. They did this in order to be consistent with the Sparrow framework; not sure why Flash people should care but hey, what can you do…

Also if you are looking for filters on display objects, stop looking it’s not there.

Finally the is 2 great new properties on display object pivotX and pivotY which allow you to change the origin point which is really useful in rotations and scaling.

Well that is it for now, as I play more with it I should find more stuff and I will edit this post. Also, I will be working on a book soon, so I might not feel like writing on this blog too ( you know, like writing too much in one day).

, , ,

3 Comments


My views on Adobe licensing the use of Stage3D in conjunction to the memory opcodes

I have been reading about this an nothing I found was really expressing what I fell about it. The thing is I never really had a project that could benefit from using the opcodes. I mean I have built rich experiences for the past 5 years and some of my projects were pretty complex. Stage3D I would use, big time, but not to build some crazy 3D world, I don’t have the 3D skills for that. My point being, in the state that it is in I don’t think I would ever use the memory opcodes and I believe it is so for 90% of the developers out there. Now I know that on the Flash roadmap from Adobe they are planning to give easier access to the memory opcodes, maybe that will change my views on this, but it hasn’t been done yet.

Lastly, on the 9% thing, this is the amount of money you must give Adobe once you have made more than 50k revenues using Stage3D and the opcodes, I think it’s fair. I think the Unreal engine has a similar licensing model, where you don’t pay anything unless you have made 100k. If I ever come to have to pay the fees, it will be a problem that I will be happy to deal with as I will have some kind of success anyway. What do you guys think? Am I a senseless individualist bastard or do you agree that it is mostly the elite crying out?

, , ,

2 Comments


Optimizing Flash for the iPad

You might know that I am making a game for the iPad and it’s nearly done. The thing is, I also want to publish it on the web, you know, make money from sponsorship too. Actually, I think it might be the only way I make money with the game as the iPad app market seems really hard. Plus it will also cost me money to publish in the Apple app store (developer account), so I think I might be loosing money going that way. Anyway, I was testing my game for the web first and everything was working fine. I tested on the iPad after and that is when things started to get hairy.

Yeah, an iPad (iPad 2) is not a full fledged computer (funny to say this considering my first computer was a 486), so it is not as fast. Well I have seen some pretty crazy shit on the iPad, like the Dead Space game so I guess it can be pretty strong. This only means that the Flash player isn’t that great on it, probably because it doesn’t use the GPU. So as I was testing my game on the iPad, it started out working really great, but as the game went on, more and more objects got drawn onto the screen and that is when the performance started to go down. So I set out to optimize my code.

Object pooling

Object creation in Flash is an operation that is costly and since I hadn’t optimized anything yet, I was recreating every object on the screen every frame. There is a possibility of having 240 objects on the screen at the same time, so that’s a lot of object creating every frame. To minimize this, you can do object pooling, which is having a pool of already created objects and change their properties instead of creating new ones. I did just that and it went really fast to implement. The thing is, when I tested it on the iPad, it made no difference at all.

Blitting

Another thing that is heavy on the CPU in Flash is updating graphics, so I tried to optimize that part. Blitting is a technique by which you compress all your visual into only one Bitmap that you draw on the screen. So instead of having multiple display objects being redrawn (in my case 240), you only have one. Read more about blitting here. Blitting doesn’t fit well with every project (like those relying on vector graphics) , but mine was based on Bitmaps and didn’t have a lot of rotations (it did, but only 90 degrees one) so I could easily do it. I was pretty sure that this would help a lot, but it actually did nothing noticeable. I was a bit baffled here, maybe my redrawn zone is too big… It is a game for iPad so I have a full resolution of 1024 x 768, maybe that is too heavy for the Flash Player.

Code Optimization

So if it wasn’t the creation of objects or the graphics, than maybe it was the code. I had used Arrays everywhere cause it is just simpler to use than Vectors, so I changed them all. I also did some loop optimization and replaced some divisions by multiplications ( like /2 to *0.5). Also didn’t change anything…

Last Resort

My last resort was to change the game dynamics so that the game is less intensive on the CPU and that is the only thing that made any impact on performance. My game is a puzzle, so I removed 3 rows and 1 column from it thus reducing the possible maximum number of object on the screen (and also the redrawn region size, and probably also the number of computations) by 20%.

Conclusions

I’m pretty sad at this point, changing the game dynamics to optimize is not a really good decision, it’s kinda like saying let’s make the game less fun to make it run faster. What I liked about Flash is that I could compile for the web, iOs and Android with limited changes (in this case all I changed was different layouts based on size (height and width) of the game). Turns out it is not fast enough on iOs (iPad). Maybe when they put Stage3D on iOs that will do it, but till than there is no true cross development platform. I meant to look into Corona, but it does only mobile. And I really don’t want to fall into the HTML5 mess. I would really like to hear about a dev story about HTML5 and a game built for web and mobile and most importantly how much time it took to do.

, , , , , , , , , , , ,

7 Comments


Wonka – The Imagination Room

My latest project was for Wonka and is basically a 360 video player. It was fun and little and made me explore a bit. I got to play with Stage3D to compare the speed, plus I tried the new native mouse cursor (MouseCursorData). None of that made it in the final site but still was fun to try out. So here you go explore the Imagination room and don’t forget to look around:

Wonka – The Imagination Room

, , , ,

4 Comments


Away3D and Stage3D (Molehill)

I posted an article earlier this week about Away3D and the VideoMaterial and since I also made tests on Stage3D (Molehill) while doing that research, I thought I would post them here. My point with all this is to show that working with the new version of Away3D is going to be a little different. Here is the code to do mostly what the other post was doing, mostly mapping a texture to a sphere and having the camera in the middle (not a video here, just a bitmap).

public function Main(){
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
 
  view = new View3D();
  addChild(view);
 
  view.camera.z=0;
  view.camera.y=0;
  view.camera.x=0;
  view.camera.lookAt(new Vector3D(0,0,1));
 
  light = new PointLight();
  light.radius = 200;
  light.color = 0xffffff;
  light.castsShadows = false;
  light.position=new Vector3D(0,0,0);
  view.scene.addChild(light); 			
 
  spherecontainer = new ObjectContainer3D();
  view.scene.addChild(spherecontainer);
 
  var material : BitmapMaterial = new BitmapMaterial(new Albedo().bitmapData);
  material.bothSides = true;
 
  sphere = new Sphere(material);
  sphere.radius = 500;
  spherecontainer.addChild(sphere);
 
  addEventListener(Event.ENTER_FRAME, _handleEnterFrame);
  stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
  stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}

To get starting for Molehill I followed the simple instructions and used the FDT template found on the powerflasher’s site. As you can see if you compare the code, there are some differences. You don’t need to create a scene and a camera, they are already there for you. You need a light and you add that light as any 3D objects (no more using addLight). Lastly, which was my biggest problem, your texture need to be a square otherwise it won’t show. That was really bad for me cause I wasn’t seeing anything and the textures I was using were working fine in Away3D 3.6. But in the end I made it work. Anyway, Adobe needs to release that shiz fast cause it’s awesome!

, , ,

No Comments