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

10 years ago by dlkulp

Where and how do I do this? I can't put it in game because that doesn't exist yet, so I thought about making a simple controller entity that everything extends from but I'm getting undefined errors. Is there a simple way to run logic using the impact libraries that will be accessible when setting properties of entities or in the init function of entities?

10 years ago by dlkulp

made a controller entity that everything extends from:
ig.module(
	'game.entities.Controller'
)
.requires(
	'impact.entity'
)
.defines(function () {
    EntityController = ig.Entity.extend({});
})
var globalVar;

main loads this first and because everything extends from it the globalVar is accessible in all other entities where ever I need it. Not the best solution I'm sure but it works well.

10 years ago by dungeonmaster

Can you explain a bit more? I didn't understand what you are trying to do.

10 years ago by dlkulp

have a variable that can be accessed in the init functions of all entities that uses core elements (ig.ua or ig.Entity or anything already loaded).

10 years ago by Joncom

Game properties are available to entities during init.

// lib/game/main.js
MyGame = ig.Game.extend({
    info: 'This is available to all entities.'
    ...
});

// lib/game/entities/example.js
EntityExample = ig.Entity.extend({
    init: function(x, y, settings) {
        console.log(ig.game.info);
    },
    ...
});

10 years ago by dlkulp

@joncom that was not my experience. I thought the same thing but using your code (or my previous code) gives me an "ig.game is undefined" error.

10 years ago by Joncom

I believe something has gone wrong, because your entities should be able to access the ig.game instance. Mind sharing your code (minus the impact library) so we can take a closer look?
Page 1 of 1
« first « previous next › last »