1 decade ago by Xaan
I'm a little bit confused about how you would go about using classes and extending from them with Impact. Keep in mind, I did read the documentation.
Say I have a player entity. I want the player entity to extend an entity called controllable - so that all of the handling of input and movement is done within the controllable entity. Should controllable actually be a class, instead of entity?
Say it is supposed to be an entity - so I create a new entity in a file called 'controllable.js', this entity of course extends impact's entity object (ig.Entity.extend({ ... ). I call this entity EntityControllable so that it complies with the file name, and then have its update function handle all movement.
Now, when I want to increase the x velocity of the player entity (which will extend this controllable entity) should controllable's update function refer to this.vel.x, or this.parent().vel.x?
Now how do I actually go about making the player entity extend the controllable entity? I tried making it:
EntityPlayer = ig.EntityControllable.extend({ ...
After requiring game.entities.controllable, but it just doesn't work. The game doesn't load.
Finally - a question about classes. How would you go about using classes with Impact? For example, where do I save classes, and how do I require and extend other classes and entities with them?
Also, in the docs, all the examples have classes be local. For example:
var Person = ig.Class.extend({...
But how would I go about making it independent, in it's own file, so that it can be required and then used with other classes and entities.
Thanks for your help,
Xaan
Say I have a player entity. I want the player entity to extend an entity called controllable - so that all of the handling of input and movement is done within the controllable entity. Should controllable actually be a class, instead of entity?
Say it is supposed to be an entity - so I create a new entity in a file called 'controllable.js', this entity of course extends impact's entity object (ig.Entity.extend({ ... ). I call this entity EntityControllable so that it complies with the file name, and then have its update function handle all movement.
Now, when I want to increase the x velocity of the player entity (which will extend this controllable entity) should controllable's update function refer to this.vel.x, or this.parent().vel.x?
Now how do I actually go about making the player entity extend the controllable entity? I tried making it:
EntityPlayer = ig.EntityControllable.extend({ ...
After requiring game.entities.controllable, but it just doesn't work. The game doesn't load.
Finally - a question about classes. How would you go about using classes with Impact? For example, where do I save classes, and how do I require and extend other classes and entities with them?
Also, in the docs, all the examples have classes be local. For example:
var Person = ig.Class.extend({...
But how would I go about making it independent, in it's own file, so that it can be required and then used with other classes and entities.
Thanks for your help,
Xaan