YouTube Basic Sidescroller Tutorial in FlashDevelop
As I’ve made up my mind to learn Flash, and don’t want to pay a honkin’ amount of cash, I decided to go with a free Flash IDE called FlashDevelop.
Since I’m toying around with the idea of sidescrollers, I did a search for “Flash sidescroller tutorial” and found this excellent 3-parter by devnote.org. Unfortunately (for me), the tutorial expects that you’re using Adobe’s Flash IDE. Thus, as a contribution to the web (and myself… mostly myself), I translated the tutorial to work with FlashDevelop. Read on to see how I did it, or just grab the source here.
There are basically only 3 elements in the DevNote tutorial that require the Flash IDE. They are the Boundaries, Player and StartMarker MovieClips.
As the StartMarker was just a point, I used the Point class to represent it (and called it _startPos instead). Since Boundaries and Player were basically sprites, I represented them using the Sprite class. Here is the pertinent code:
public class Main extends MovieClip { private var _startPos:Point; private var _player:Sprite; private var _boundaries:Sprite; ... public function Main():void { // Assign defaults. _startPos = new Point(100, 10); _player = new Sprite(); _player.graphics.beginFill(0xff0000); _player.graphics.drawRect(-10, -50, 20, 50); _player.graphics.endFill(); _player.x = _startPos.x; _player.y = _startPos.y; addChild(_player); _boundaries = new Sprite(); _boundaries.graphics.beginFill(0x0000ff); _boundaries.graphics.drawRect(40, 100, 110, 20); _boundaries.graphics.drawRect(100, 150, 110, 20); _boundaries.graphics.lineStyle(20, 0x0000ff); _boundaries.graphics.moveTo(200, 300); _boundaries.graphics.lineTo(500, 100); _boundaries.graphics.moveTo(500, 100); _boundaries.graphics.lineTo(600, 100); _boundaries.graphics.moveTo(800, 200); _boundaries.graphics.lineTo(500, 200); _boundaries.graphics.endFill(); addChild(_boundaries); ... } ... }
I also change the code slightly in the case of the key handlers (I used constants for the key codes isntead of magic numbers) and used a do ... while loop for the collision detection.
Comments(0)