Grant Skinner++
Great post by Grant Skinner on Adobe’s decision to refocus their energy away from the mobile browser. Give it a read, it’s a nice break from most of the ranting you’ll read today…
Zombies
I just finished a very quick and easy site for the Utah Highway Patrol at www.zombiesagainstdrunkdriving.com. For the last couple of years, the Utah Highway Patrol has been running various campaigns like this to basically push their message in funny and interesting ways and to try to curb drinking and driving. I’m almost surprised that this idea made it through, but it’s fun to see them keeping up the tradition of being a little more lighthearted.
Happy Halloween!
What to do today…?
For me, that’s often the question I ask myself more often than anything else. It’s not that I don’t have anything to do, just the opposite. I have lots of things I would like to do, quite a few things I should be doing, and a whole bunch of things that really need to get done.
The real question revolves around these issues:
Should I spend time making money…
Should I spend time learning something…
Should I spend time developing something that might make money… be fun… be useful to someone…
That’s where I get tripped up. Lots of things that might be worthwhile and a lot of things that I should be doing.
There are no answers here, only thoughts…
Simple Animation for Games: part 1
The first time I ever played with the idea of making a game in Flash, was when an advertising firm asked me to modify another developer’s code to fix some problems they were having with the game. It was a simple AS2 game all written on a single frame. It was pretty messy code, but what I remember most were a bunch of calls to the Math class and thinking, “Whoa, math.” Not just math, but cos and sin and a bunch of other trig functions that, at the time, made no sense to me.
As I sat there thinking about how in all my wild imagination, I had never even considered the idea that real math would ever actually be useful in my life, it occurred to me that I might need to pick up a book and try my hand at some math. It didn’t take long to realize that I didn’t need to become a mathematician or really even need to understand trigonometry, I just needed to understand the bit of it that’s useful for building games. Of course, you can always learn more and I’ve picked up a lot of tricks over the years, but there’s a couple of simple building blocks that you don’t even really need to understand, you just need to know how to use the code.
Of course, it always helps to understand what the code is doing and for that, I’d recommend any of Keith Peter’s books on ActionScript Animation. In those books, Keith documents most of the formulas and techniques (more or less) that I’m going to demonstrate in this series and does a good job explaining things in a way that’s understandable to non-mathematicians. It’s a really good read and I use it as a reference on a regular basis. But today, we’re not going to talk trig, we’re just going to see how it’s done.
Smooth Back and Forth Motion:
I come across this all the time when I’m building a game. I need a platform to rise and fall in a regular pattern. Something needs to swing back and forth, or walk back and forth, etc. I do this so often that I don’t even think about the code anymore and what it’s doing. Sure, I know that I’m basically using a sine wave which I’ll use to output a very smooth numeric change from 1 to -1 which I’ll then multiply to blah, blah, blah… Here’s how it works: Our case study will be a platform that needs to rise and fall. It needs to do so very smoothly and naturally.
And we do it like this:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class UpDown extends MovieClip {
private var speed:Number = 0.05;
private var angle:Number = 0;
private var range:Number = 100;
private var startY:Number = 200;
public function UpDown() {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void {
platform.y = startY + Math.sin(angle) * range;
angle += speed;
}
}
}
Which makes our platform move like this:
There’s obviously not much code here, so what’s going on? Not much really. We have four variables:
speed – how fast we want to go through the up/down
angle – this is the number that is fed to the Math.sin() function
range – how far above and below the start position we want to go
startY – the center of the two extremes the platform will be traveling
Then, inside an enter frame loop, we have these two simple lines where all the magic happens:
private function onEnterFrame(event:Event):void {
platform.y = startY + Math.sin(angle) * range;
angle += speed;
}
All this does is tell Flash to smoothly move the platform vertically between 100px above startY and 100px below. Very simple and easy, and extremely useful. Like I mentioned, this is the kind of thing I find myself doing over and over again. And it doesn’t just work for up and down. It will work for any property you want to move back and forth, up and down, rotating one way and then the other… you get the idea.
I hope you find this as useful as I do. Play around with it and you’ll find yourself using it in all kinds of situations and your life as a game programmer will become a little bit easier.
My new friend Starling…
I’ve been playing around with Starling lately, mostly to test it as an alternative to the way we currently build our game engines. If you haven’t heard, Starling is a port of an iPhone framework called Sparrow that was written by Gamua that lets you write very AS3 friendly code while taking advantage of hardware acceleration in Flash with its new Stage3D APIs. Starling allows you to push most of the rendering off to the GPU, freeing up the CPU to do other things. It’s also very fast… like really fast.
Most of the games that I’ve seen with it have been pretty simple. Some of the tests however, have been very impressive. It feels a little foreign leaving the standard Flash Movieclip behind and working with bitmaps instead of vectors, but I have a feeling that it will become more and more common to do so. Waste put up one of their tests at: http://www.waste-creative.com/games/invaders/ that was particularly impressive and on my machine, plays 60 fps consistently. I’d be really interested if we could get something as deep as Poptropica to run in a system like this…
Of course, there are other frameworks like ND2D by Lars Gerckens that are doing similar things. I need to play around a bit more before I commit to a particular framework for a releasable product. No doubt though that Stage3D is going to have a serious impact on the way we do things.
An ODD update…
ODD Animation, like all such entities is constantly changing. A loose organization from the beginning, it’s natural that those of us who have worked together under that name and many others are constantly coming and going. The biggest change, by far, came when I accepted a full time offer from Pearson to work on Poptropica. It’s a full-time gig and the first time I’ve worked as a full-time game developer.
Poptropica is a lot of fun and I’ve still managed to work on four or five animated 90 second spots and a couple of live-action shoots. But in the last year, I haven’t had to reach outside the organizations I’m working with to find the talented people I always enjoyed working with during my stint as a freelancer. As a result, ODD Animation has been fairly stagnant for the last several years. While I’ve become very comfortable working at Pearson, a lot of opportunities have opened up recently with mobile applications, hardware accelerated Flash content, AIR, etc. and I find myself wanting to dip my fingers in several personal projects again in a big way. Several are new projects or collaborative ideas that I’d like to explore and several are new takes on unfinished business I’ve had running around my head for a long time.
For example, I’ve had an idea to build a Spanish vocabulary program for over a decade. I finally built it several years ago. But now it’s time to really finish it, if just to get it out of my head so I can think of something else. Along with that project come a dozen ideas for mobile and desktop apps and games that will take some thinking and looking to find the right people to work with. I’ve never been much of a blogger, but my intent is to offer a forum where I can begin to present some of the things we’re playing with as we’re working on them. Along the way, I might try my hand at sharing some of what we know about the technologies we play with. We’ll see whether that “Tutorials” button stays up there long…
Keep smiling,
Jason
