So I am learning how to use Haxe/OpenFL by making a platformer. Not like on the tutorial, an organised class-based platformer. Usually, when I hop into a new engine, I set up a system with an "Engine" class that has an array/list of all the game objects. I did that in this, and tested through the whole way, and only encountered a problem when I added the player object. I've never really used Haxe before now, only C++, Python, and Gamemaker. (I've done that system in all three.) I'm probably making some stupid error I didn't study about, but any help is appreciated.
So here is the main class:
class Main extends Sprite
{
var gameEngine:Engine;
public function new()
{
super();
// Make the engine
gameEngine = new Engine();
// Create a player
var player = new oPlayer(14, 14, gameEngine);
}
}
You can see we make a new player there, that is
class oPlayer extends GameObject
{
// The player's image is a, well, player...
var bPlayer:Bitmap;
// In the init, just get the image and add it to the openfl display
public override function objectCreate(newX:Int, newY:Int, gameEngine:Engine)
{
// Load the player's bitmap
var tempImage = Assets.getBitmapData("assets/player.png");
var bPlayer = new Bitmap(tempImage);
gameEngine.addChild(bPlayer);
}
}
The player class then inherits GameObject
class GameObject extends Sprite
{
// The class needs to start the Sprite
public function new(newX:Int, newY:Int, gameEngine:Engine)
{
super();
objectCreate(newX, newY, gameEngine);
// Add the object to the game
gameEngine.addObject(this);
}
// A kind of startup function that is called by new
public function objectCreate(newX:Int, newY:Int, gameEngine:Engine)
{
// This is really mostly done by the child object
x = newX;
y = newY;
}
// Some things that will be used by the engine
public function frameEvent(gameEngine:Engine)
{
// This function inheritly does nothing
}
// It's important to note that objects must draw themselves. This is not done for them.
public function drawEvent(gameEngine:Engine)
{
// Same with this one
}
}
Which uses Engine
class Engine extends Sprite
{
// This is the array that holds all the game objects
var gameObjects:Array<GameObject>;
// Create the class
public function new()
{
super();
// Create an empty array
gameObjects = new Array<GameObject>();
// Just for debug
trace("test");
}
// Add an object to the game
public function addObject(objectToAdd:GameObject)
{
// Insert said object at the end of the array
gameObjects.insert(gameObjects.length, objectToAdd);
}
}
I really hate dumping all this code on you guys, but let me help explaining.
Main function happens, creates Engine, then creates the player -> which should call the GameObject's constructor.
The full error message is
Source/Main.hx:23: characters 26-27 : Unexpected (
Source/Main.hx:23: characters 29-30 : Unexpected ,
Source/Main.hx:23: characters 29-30 : Unexpected ,
That is all the code in the project aside from the imports, so there is nothing else to post.
I appreciate any help provided.
P.S. I'm compiling to Neko.