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 we now have a bullet game object. But there's going to be a lot of bullets that are going to be flying around, so in order to keep track of them and to handle the updating and destroying we're going to create a BulletManager class, and this is the first of a series of manager classes that we're going to be creating to manage different objects. So I'm going to right-click on my main source folder and create a new ActionScript Class, and I'm going to create a package for these manager classes and I'm going to call it managers, and then I'm going to create a new BulletManager class, and this doesn't have any Superclass or interfaces involved.
So I'll click Finish, and now I'm going to stub out this manager class. So the first thing I'm going to do when I create a BulletManager is to send in a reference to our main play state, so I need an argument here to catch it. I'm going to call it play, and this is going to be of type Play. So let's create an instance variable to store that, so this.play = play; and create it as an instance variable at the top. What I'm going to need to create is an array, and this array is essentially going to keep track of all of the active bullets that are currently in my game.
And what I'm going to do is to be able to loop through that array and update all of the positions of the active bullets. So I'm going to come onto here and create a new variable called bullets, and that's going to be equal to a new Array. Now ActionScript 3 does have a vector class, which is essentially a typed array, but the thing is, currently at least in the current public Flash player, it's actually faster sometimes to use arrays, particularly when you're going to mobile, so for our case right here we're just going to use a regular array.
Now I'm going to create that bullets array as an instance variable at the top. So now I'm going to need to create a series of methods that I'm going to want to call. So the first thing I'm going to want is a public function called update, and this is going to be called from our play state. So on every frame we're going to call this bulletmanager.update. So let's say public function update, and again this is going to do things like updating the position of all of our bullets, determining when we need to fire a bullet and also when we need to destroy a bullet.
So with that update method created, the next thing I'm going to do is to create a function called fire, and this is a function that's going to be called from our update method which is essentially going to fire a new bullet. So this can be private, so private function fire, it's not going to return anything. Now the next thing we're going to want to create is a method which allows us to destroy a bullet. So let's say in our collision detection which we'll get to later, it turns out that a bullet has hit an alien.
Well in that case we want to destroy the bullet, we want to remove it from the screen, we want to remove it from our bullets:Array and when we actually get to looking at object pools, we are going to want to return that to the object pool, so it's available for the next time. So we're going to create this as a public function destroyBullet, and to this we're actually going to be passing in a bullet object which we want to destroy. So I'm going to catch it with an argument called b, and this is going to be of type Bullet, we're going to fill in these methods later.
And the last function I'm going to want to create is a destroy function, which we're going to be able to call from our play state, so when it comes time to switch to the game over state, we're going to be able to call this destroy method and make sure we clean up after ourselves and remove all of these things from memory. So we're going to create a public function called destroy, and we're going to be creating other managers, so for instance, we're going to be creating an Alien Manager we're also going to be creating a CollisionManager, and they are all going to take this same basic approach, and that they're all going to have an update method which we can call from our play state.
We're going to be able to also clean up and destroy the manager and all of its accompanying objects when we want to change to the game over state.
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.