My first racing game

Subscribe to My first racing game 4 posts, 3 voices

Sign in to reply


 
avatar for KMAE KMAE 116 posts
Flag Post

So I’m about to very slowly put together my first racing game and would like to know opinions on scrolling the background to keep the camera player focused. Are you guys moving the background around the player or what? Also I haven’t checked out the lab that has come online so is that something worth checking out? I did play it and see that it has some basic side scrolling but the background seems to repeat whereas my track would be interactive (hitting the sides and such) Thanks for any ideas. Currently I would make the background move around the player (a la Futurama) but if there’s a better way please tell :)

 
avatar for billowillo billowillo 14 posts
Flag Post

ya its definately worth checking out, it teaches all about scrolling backgrounds ( if your using as3 instead of as2 theres a link for an as3 example at the bottom)

 
avatar for Salman Salman 26 posts
Flag Post

Hi KMAE,

Thats awesome! Well it turns out, I’m starting a series of articles on making a multiplayer car game. Please check out my blog at http://actionscriptdeveloper.blogspot.com/. This particular topic will be covered in my blog one day, but for now, I will answer your question here:



Create a Camera class, that takes in its constructor 2 DisplayObjects. Call the first one ‘reference’ and the second one ‘trackThis’. The idea is that you want to attach a camera to some display object (trackThis), and you want it to be the center of some other display object (reference). So, you’d pass the Track DisplayObject as the reference, and the Car DisplayObject as the thing you want to track. On the track, set its ScrollRect property to be the width and height of the stage, and if you use the Model-View-Controller architecture, then you can easily have multiple ‘views’ of the track, each with a different ScrollRect, allowing features such as split screen. Anyhow, in every frame, just invoke the following method in the Camera class:

public function doStuff() :void
{
var x :Number = trackThis.x;
var y :Number = trackThis.y;

var width :Number = reference.scrollRect.width;
var height :Number = reference.scrollRect.height;

var rect :Rectangle = reference.scrollRect.clone();
rect.x = Math.min(reference.width – width, Math.max(trackThis.x – width/2, 0));
rect.y = Math.min(reference.height – height, Math.max(trackThis.y – height/2, 0));
reference.scrollRect = rect;
}


Enjoy! More detail will be covered by my blog. Stay tuned…

 
avatar for KMAE KMAE 116 posts
Flag Post

Thanks so much, Since I am taking my sweet time with this one I may not get to look at it for a bit. It looks confusing at first but I’m sure I can make it out. My experience comes from programming simple java programs in school. The 4 games I’ve made before are my first :) and I haven’t as I said before done any scrolling yet. I am using AS2 right now just because I was using the Flash game programming for dummies book that is fairly old. I’ll certainly have to check out your blog too.

Also thanks billo!

Sign in to reply


Click Here