background preloader

Flash

Facebook Twitter

PBE at 360|Flex and the Flex Show - PushButton Engine. Tutorials. AS3 Character Movement: Following Mouse with Easing. Honestly this is an addendum to the previous tutorial in this series. This is a simple adjustment to the code we have already wrote but it will give us character movement that eases towards the mouse position instead of keeping a constant speed. It’s a relatively useful effect, I used it in one of my games, Entropy, for the opponent’s paddle movement. So here we go, let’s make our character follow the mouse easing its way into the position.

First grab this source code: As3 Character Movement: Follow the Mouse Source code This is the final source code from this tutorial: AS3 Character Movement: Follow the Mouse Controls Alright so just ignore the Engine class. We don’t need it. And testing our movie we get this: Okay but if you read the previous tutorial, this is nothing new. Alright, get this… you can delete everything in the loop.

We only need two simple lines to make our easing work. Simple huh? X -= (x – stageRef.mouseX) / speed; This does all the magic. So our change in x was 21.428. The Display List, The Stage, and "addChild" in Flash CS3. The "Display List" is the hierarchy of graphical objects in your movie to be displayed on screen at runtime. The hierarchy is created via parent-child relationship between objects.

Parts of this hierarchy are created automatically by the Flash Player. For example, the top object in the hierarchy, called the Stage, as well as the MainTimeline are created by the Player. Other parts you create knowingly or unkowingly when you draw objects at authoring time. When you create parent-child relationships between objects via "addChild" method in your ActionScript 3 program, you consciously create and control parts of the Display List. Here is the Display List of our "solar system" movie shown on the previous page. As you see, when you draw or create text fields during authoring time, your are adding children of the MainTimeline to the Display List.

This.addChild(sun); or equivalently: addChild(sun); trace("Number of children of Stage: "); trace(stage.numChildren); trace(stage.getChildAt(0)); Download. Registering Hit Tests with hitTestObject. Okay so hit tests. Hit tests simply are a check to see if two objects are touching one another. There’s plenty of ways of doing them and every shooter game needs them. AS2 had a nice little function called hitTest, AS3 has two functions…. hitTestPoint and hitTestObject. So what’s new about this hitTestPoint and hitTestObject and which one do you use? We’ll discuss it and how to make our bullets hit enemies and enemy bullets hit us.

This post is one of many in a series titled AS3 Flash Games for Beginners. First of all, I’m probably going to setup our Hit Test a lot differently then you’ve seen in the past. So here’s what we are going to do. Green Box representing our hit area of our Ship Okay, right click our box then Convert to Symbol… and name it hitBox then make it a MovieClip with the Registration in the center. Setting up an instance of our hitBox MovieClip Nice, now guess what? Large hit area for our enemy ship Just name the instance of the box hit like we did before. To this: Collision detection methods, hitTest and hitTestObject alternatives.