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 paulh

Noob questions, i know :-(

when is it right to use:

ig.game.extend.
ig.class.extend
ig.entity.extend

I basically haven't used class extend at all ... and have used ig.game.extend... and i cant tell you why though really.

My thoughts are:

Regardless if its a seperate .js then they have to be included in the requires of main.js.
that you could just define a class as say var Person = ig.Class.extend and save that as person.js.... does that mean you can access anything in the class at anytime .. i dont really get it from the documentation.

Entities i get ( i think) i spawn one when i need one and kill it when im done with it .. but is that the same with classes is everything loaded at the start? So if i had a var pauls.name in a class is that held in memory at all times and i can call it or does a class have to be "spawned" like an entity ..

Lasty ig.game.extend im not sure why i used that .. i wanted to get me main game logic out of main.js so it wouldn't get too cluttered when i add all the permutations for the different device etc .. was that a bad idea? Im thinking that ig.game.extend is like loading totally new subset of the game, so when i gointo say menu mode .. i could have a menu = ig.game.extend and then options, the same and then a different game.extend for each of the different game modes.. AM I INSANE/HAVE NO IDEA WHAT IM TALKING ABOUT/ALMOST GETTING IT/WILL NEVER UNDERSTAND.

Thanks for your time and patience!

1 decade ago by Joncom

I think the key concept behind extend is inheritance.

It's very helpful any time you want to make multiple things that share a lot in common, but you don't want to write a lot of duplicate code.

An example of this is an Entity. Every entity is drawn, updated, moved, traced for collisions, etc. all the same way. So when we make a new entity we say EntityNew = ig.entity.extend...

So now even if we left our new entity completely empty it really is not empty at all. It contains everything (vars and functions) that you'd find in the lib/impact/entity.js file.

Hope that helps a little.

1 decade ago by Arantor

You generally won't inherit the basic class type, Game and Entity themselves do, and you'll inherit from them; your game's entities will inherit from the master Entity type, your game will inherit from the master Game type.
Page 1 of 1
« first « previous next › last »