I am creating a game engine for HTML5 Canvas with javascript for personal use, however I am running into a problem. I have created a entities class with a super constructor and a few functions (like remove and add new entities) as well as a update and init function within the class. However when I run the main init at the end of the code, with entities.init(); it reports an error and says it is not a function, even though I'm sure I made it public. Here is the code
function entities(){ //Entities class holds all objects that: take damage, move,and do things that a static object could not.// //A list of all current entities in game// var entitiesList = new Array(); //Allows removal of an entitiy from the game, and the current list of entities// function removeEntity( id){ //snip!// } //entity superclass// function entity( name, spriteName, HP){ //snip!// var updateEntity = new function(){ console.log("UPDATING Entities") //drawSprite(sprite, posX, posY); if(this.timer > 0){ this.timer = this.timer - 1; }else{ removeEntity(this.entityID); delete this; } if(this.health == 0){ removeEntity(this.entityID); delete this; } } } //Method to create a new entity// function createNewEntity( entName, sprite, posX, posY, HP){ //snip!// } var damageField = new function(radius, power, posX, posY) { //Damage any entities within a "square" radius of an entity. I plan to add radial version later// //snip!// } this.init = function(){ console.log("INIATING ENTS"); createNewEntity("NUGGET", "chaingun_impact.png", 250, 250); } //update function for superclass update function to call// this.update = function(){ entity.updateEntity(); } } The main init function
function init(){ pushToSheetList(); jsonParser(); entities.init(); } Also I am 99.99% sure that the update function is not called either it is the same code pretty much just update() instead.
I am really not sure what to do, unless I want to make it so every sprite on the screen is hard coded manually, and no one wants that for a reusable engine.