Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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

1 decade ago by Xaan

Well, as far as the player entity extending the controllable entity, it was an impact syntax error. I did ig.EntityControlalble.extend, instead of just EntityControllable.extend.

If someone could still answer my questions about the usage of classes within impact, that would be great.

Thank you,
Xaan

1 decade ago by UltimateBrent

If you're doing entity extensions, the "base class" should still be an entity.

For instance, Bat extends FlyingEnemy extends Enemy extends Entity. That's overkill obviously, but you get the idea.

Each one of those would be its own file in the Entities folder. You don't have to do anything special to make them extendable, just extend them and you're done.

1 decade ago by Arantor

For example, where do I save classes, and how do I require and extend other classes and entities with them?


You can actually save classes wherever you like. At the top of each class, you have the defines() and requires() calls, and the name used indicates how it should be loaded.

E.g. if you define an entity as 'game.entities.myentity', it's going to look in lib/game/entities/myentity for it. Impact will deal with all the loading for you in this case, when you set the requires(), it will make sure that everything required is already loaded for you, which is how you are able to load dependencies (e.g. if you have a class that is a simple entity, it only requires impact.entity, but if you have your own entity base because of custom code, your later entities will only require the custom entity, which in turn will require the impact.entity class)

Any block of functionality, generally, should be wrapped into a class, and really an entity is just a specific branch of class (it's a class whose functionality centres around a game object that will potentially move every frame)

1 decade ago by Xaan

Thank you, this makes things much clearer.

I wonder what does it take to write your own "requires" algorithm... Not that I would want to replace the one that impact already has, just curious about how dominic did it...

1 decade ago by Arantor

Take a look at Impact's code, it should be in impact.js if I remember rightly.
Page 1 of 1
« first « previous next › last »