Box2D platform engine alternative
2009-10-18 00:00:00 来源:WEB开发网Everybody should know Box2D is the best engine you can use to make a platform game.
Rick Triqui, my latest game, was made with PlayCrafter that uses Box2D, and I’m starting to code my own Box2D platform engine.
Luis Fernando Silva, author of the upcoming Darkness game (Sponsors! Contact him to see the work in progress! Awesome idea!) wanted to share with us his Box2D platform engine, that made from scratch.
The source code is fully commented, for our pleasure
This is the main file:
package {
import flash.display.MovieClip;
// Import the levels from the 'Levels' folder:
import Levels.*;
public class Main extends MovieClip {
// The game level, re-instanciate this object to
// switch the levels
public var level:GameLevel;
// Keyboard listener, got the script at Emanuele's websote
public var keyboard:keys = new keys(stage);
// Constructor, here these 3 simple lines of code create the level
// and prepare it to be player
public function Main() {
level = new Level1(keyboard); // Create a new level, Level1, in this case
addChild(level); // Add it to the display object
addEventListener("enterFrame", Update, false, 0, true); // Add a loop
}
// Update the game here using GameLevel.Update so you can do
// some general stuff on a main loop instead of using the GameLevel.
public function Update(e:*) : void {
level.Update();
}
}
}
更多精彩
赞助商链接