Skip navigation

Game developers often wants to keep an entity (usually player controlled entity) in their game to be always at the center of the screen. Imagine you are playing Mario Bros. Wherever you move mario, he will always be at the center of the screen. The background is moving to keep mario’s location presistency.

Today, I made a class to do just that easily. Before I explain the usage and technical details, you may want to see the demo first (pardon the artistic side of the demo ;)). So here it is :

View the Demo of Game Camera Class.

This class is actually very straightforward. You need to instantiate it then call .to(); to do the pan and zoom.
Here is the contructor :

public function GCam(canvas:Sprite, bound:Rectangle)

This class takes 2 arguments to construct, they are :
canvas – Sprite that serve as container for all of your game entities
bounds – a rectangle object that define the boundary of your world

This class takes boundary to know how much it is allowed to pan. This is very useful, because you always want to limit the panning of the camera so that it will not expose area outside your stage.

This class only has one function :

public function to(x:Number, y:Number, zoomAmount:Number, duration:Number):void;

This function takes 4 arguments, those are :
x – the x position of point that will be at the center of the screen
y – the y position of point that will be at the center of the screen
zoomAmount – how much will the camera zoom (think of it like scaleX and scaleY in sprite)
duration – how long will it take to do the zoom and panning

This function can be used neatly to center any of your game entity like this :

_gameCam.to(entity.x, entity.y, 1.0, 1.0);

You may notice that, Yes, it does tween to do the panning and zooming. So you will get a smooth panning and zooming. However, you may pass 0 to the duration to make it choppy.

This class depends on open source tweening engine TweenLite to do the tweening. Make sure you have it before you use this class. If you don’t have it already, you can click here download TweenLite.

Well, that’s all, actually. Feel free to download Game Camera Class.

Advertisements

Today, I tried to make a random city name generator class for my game AS3 game project. After googling for city names resources for a while, I accidentally ran into this great little tool to generate city names.

This tool can generate any number of city names depends on your need. The results are also good enough. This gonna be more than enough for my random city name generator class 🙂

You can download this little application here.
Here is the original forum thread where I ran into.

Anyway, these are random city names that just generated :

Babylotte
Big Hume
Blue MacKissocklotte
Bogart Hill
Cattle Valley
Cold Babbittfield
Cold Shannybank East
Condition Coast
Crowdbury
Dust Park
East Barker
East Souderswell Mills
Eder
Frisby Mountain
Grand View
Greater  Town
Greater Overbeylotte
Hot Banehurst Lodge
Hot Nelsonana Heights
Hot Staub
Irishron Bluffs Bayou
Lamplotte
Little  Bluffs
MacWhirter
Mailbox Island
McFater Bluffs
Measure Rocks
Meeks
New Underhayboro Butte
Oberholtzerapolis
Pancake Butte
Pfefferridge
Pollutiontree
Port  Spring
Purposeboro
Red  South
Red Gundersonshire Cove
Schatzlyn Grove
Signridge
Tacktown
Teacher Brook
Tongue Woods
Traxlercott
Watkins
Year North
Yorkester

content has moved to my new website.
sorry for the inconveniences