Viewers: in countries Watching now:
Join Lee Brimelow in this project-style course that teaches how to build a Flash-based game with Flash Builder 4.6, Flash Player 11, and the Starling framework. Starling, a pure ActionScript 3.0 library for advanced graphics, extends Flash Player 11's support for the modern GPU (graphic processing unit) to enable visual presentations and games in the browser or as a mobile app.
Starting with installation and configuration of Starling and creation of a Flash Builder project, the course shows how to prepare and import graphical assets, create MovieClip classes from sprite sheets, manage various gaming objects, detect collisions, and add both particle and sound effects. The finished game can be deployed to any browser or mobile device that integrates Flash Player 11, which was released in September 2011.
So now I want to take a couple of minutes and just go over a couple of optimizations that we can do to our game, and also just in general how you might want to optimize Starling content. So first of all Starling has blend modes associated with it on display objects, so if you have, let's say, a background image that doesn't have any alpha in it, you don't need to worry about that, you can set your blendMode to none, and you will get some performance increase from doing that. So in our background class where I have these two image objects, what I'm going to do is first set sky1, I'm going to set its blendmode = and get a constant out of the Starling.display.BlendMode class, and we are simply going to set it to BlendMode.NONE.
And I'm going to do that also for sky2, and that's just a little thing but will give you some performance increase because again we don't need to worry about blend modes on those background images. Now another area which we can optimize quite a bit is in our CollisionManager class, because remember this update method gets called on every frame, so that's 60 frames per second that we're checking for these collisions, which is way more than we need to actually check because we don't need to be checking for a collision 60 times every second.
So we can reduce that a little bit. Now I'm going to show you how you can do that. I'm going to create a class property up here, private var, and I'm going to call it count. It is going to be type integer, I'm going to set it to 0. So at the bottom of our update function, I'm going to increment that every time we come in here. And now I'm going to test if count is an odd number, then we're going to do the bulletsAndAliens collision detection check. If it's an even number we'll do heroAndAliens, that will make it happen at least half as much, but we could reduce it more but for this we're just going to do it like this.
So I'm going to create an if statement. Now a really quick way to test if a number is even or odd is to say if(count and we can use the bitwise & operator, if(count & 1, that's going to mean it's an odd number, so we're going to do bulletsAndAliens and then we're going to do our else statement. And if it's an else, if it's an even number, then we're going to check heroAndAliens. So again, this will make it so each of these collision checks only happen every other frame, which will give us some performance increase, and again, you can adjust this to maybe happen every four or five frames, again depending on how things are working in your game, but this will give us some nice performance increase.
Now another thing that we can do is to set the touchable property of display objects to false, if they don't need to be interactive, meaning, we don't need to click on these items. Now in our game, again, since we're using the mouse events on the actual stage we're not going to need to listen for touch events on any of these objects in our play state. Now in the GameOver and Menu states we have those buttons so we're going to need to do that, but in our actual play state, we can come here in our constructor, and actually just say touchable = false; and that will trickle down to all of the other objects that are actually in our play state.
So if I actually try this now, you can see that everything is still working fine in my actual game, because again, we're listening for those mouse events on the stage, and we're not needing to interact with the mouse on any of the objects actually inside of the play state. So again those are some things you can do for performance. A really important one, of course, is using object pools because while you may not see a huge difference on the Desktop, if you were to take this game on to a mobile device, you would see a lot of stuttering if you weren't using object pools for your game.
There are currently no FAQs about Building Flash Games with Starling.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.