Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So in the last movie we created our basic Flash Builder ActionScript 3 project which is going to serve as the basis for our game. Now we want to modify this main Spacer class that is essentially our default class that gets launched when we run the game. The first thing I am going to want to do is to put in some SWF metadata up here, and this is going to allow me to control the width, height, background color and frame rate of our actual game. So I am going to start putting that in and first thing I am going put in is the width and our game is going to be 800x800, put in a height of 800.
We are going to set the frame rate of our movie to 60 frames per second. Now if you are used to regular Flash, you might think, wow! That's a really fast frame rate, and you can now reliably use 60 frames per second, again, because since Starling is running on the GPU we can get that really fast performance. And I am going to set the backgroundColor of my movie to black like that. So now we have our SWF metadata set up. Now you'll notice that this class extends flash.display.Sprite, which is the main display object container that you are used to working.
But when you are working with Starling, you are not using the regular display list, because Starling has its own version of the Sprite class, its own version of the movie clip class. So this main class that you come into essentially all that it does is to launch your Starling instance, which will be handled in a different class. And once you are in that class, you are no longer using the regular Flash display list. So in the constructor here, what we first we need to do is to create an instance of the Starling class.
You can call it whatever you want, but I usually call it star, so I am going to say var star and this is going to be of type Starling equals new Starling. And to this we can pass in a host of different properties. The first is that main class, the ActionScript class, which is going to be our root Starling instance. We haven't created that class yet, but we are going to call it Game. Now the next is which stage object do we actually want to render our Starling instance? Well we want to render it in our main stage for this class.
So we can simply pass in the stage object like that. Now those are the only two parameters that we are actually going to be sending into the constructor. Again, first is the main class, which is going to be our Starling root, and then the main stage in which we are going to be rendering our Starling instance. But just to look at some of the other parameters, we can actually provide a viewPort Rectangle if we wanted to render Starling into a certain rectangle of that stage. Some other more advanced properties are a Stage 3D instance, so if you are working with low level Stage 3D objects, you can actually give it a custom Stage 3D object to use for Starling.
But in typical cases, you are not going to need to use this parameter at all. Now the last parameter is called render mode and this is an interesting one because Stage 3D can actually run either using the GPU or it can actually render in software mode. So if somebody goes to your game and they don't have a supported graphics driver, they are actually going to be viewing your game in software mode. So if you wanted to force software mode so that you could test out how it performed, you could actually send in software for that string.
But again, we are not going to need to do that, so we are only going to send in these two arguments. Now another nice feature of Starling is that it has a build in stats class. So often, as you are building your Game, you are going to want to see things like what is the current frame rate, or how much memory is my game currently taking. And while you are debugging that can be really helpful. So to show that we are going to say star.showStats = true; and obviously when you go out and publish your final game, you are going to want to remove that, because typically you are not going to want to show those stats.
Now this Starling instance can be started and stopped and this is useful, let's say, if the user navigates away from your game, you can actually stop the Starling instance, which will stop everything about it and then you can restart it when the user returns to your Flash movie. So we are going to go ahead and start that Starling instance and what this is going to do is essentially going to now call this Game class and that will be now our root Starling class. Now just to show you some of the other properties that are available on the Starling instance, we have things like being able to set a custom antialiasing amount. We can actually scale content up.
This is useful on mobile, like if you are dealing with, let's say, a second generation iPad and the new iPad with the retina display, you can actually use that scale factor to scale up your content appropriately. You can enable error checking; this is particularly for Stage 3D methods. You don't want to do that unless you need to, because it can have a negative performance impact. If you need to get to or have a nativeOverlay, if you want to add traditional regular Flash display list content over your Starling instance, you can use this nativeOverlay.
We can get access to the nativeStage object, which we will be doing later on in the course. Another interesting feature is the ability to simulateMultitouch. So Starling was built with mobile in mind. So it has Multitouch classes available and if we simulateMultitouch to true, we can actually, by holding down the Ctrl key, enable multiple touch points and see how they interact. So definitely look through all of the properties in the documentation. In our case here, all we are going to do is simply turn the stats on and then we are going to start off our Starling instance.
And in the next movie we are going to go ahead and create our main Game class.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105272 Viewers
56 Video lessons · 117035 Viewers
71 Video lessons · 86229 Viewers
131 Video lessons · 41222 Viewers
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.