0

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.

2 Answers 2

2

You need to create instance of your entities class.

var oEntity=new entities(); oEntity.init();//call init method. 
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to have worked, for now , I'm not sure if for say I have a map class that contains map data, and there is a entity spawner if I were to call createNewEntity would actually work, I guess I will see later.
1
 var en = new entities(); en.init(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.