Moveable head and scrolling background – A beggining

by Brandon on Aug 28th in Flash / ActionScript

I have only recently started learning flash again. A couple of years ago I spent a little time learning action script 2.0, though since then have forgotten most of it. Thankfully I found a few interesting books and have been enjoying the relearning process, even if the language is similar to other languages I have experience in like Java.

This here is my first little fun project in Flash. I find that if I make games while learning a new language, it increases the learning speed and is obviously more fun.

Get Adobe Flash player

Right now it’s nothing more than a simple square head that you can move around the screen. Well, not exactly. The head never moves but the background behind it. This is the basics of screen scrolling – the same thing found in many of the old school 2d games like the super mario bros. Here is an example of the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(backgroundIMG.x + backgroundHalfWidth < stage.stageWidth)
{
	backgroundIMG.x = stage.stageWidth - backgroundHalfWidth;
}
else if(backgroundIMG.x - backgroundHalfWidth > 0)
{
	backgroundIMG.x = 0 + backgroundHalfWidth;
}
 
if(backgroundIMG.y - backgroundHalfHeight > 0)
{
	backgroundIMG.y = 0 + backgroundHalfHeight;
}
else if(backgroundIMG.y + backgroundHalfHeight < stage.stageHeight)
{
	backgroundIMG.y = stage.stageHeight - backgroundHalfHeight;
}

I eventually plan to add things to it, improve the scrolling so you can reach the borders, add enemies to avoid or fight and finally add some goal or point for the player to play (item collection, score or something of that nature).

One Comment

  1. mcdonalds coupons

    13th September 2009

    Thanks much for that informational entry.

Leave a Reply

Prepared and Owned By Brandon
All Rights Reserved