1 decade ago
by ad34
Hello,
How can I call a method that I ve build in a class which extends from ig.Game.extend inside an entity ?
ex:
I want to call the method when a key is pressed
// inside enity
update: function ()
{
if (ig.input.pressed('somekey')
{
// call the method "some action inside class which inherits from ig.Game.extend
}
thanks in advance
it should be the Game which 'ask' something to its entities and call its own method. Impact is based on this idea of a main loop within the game, which has control over its entities (it calls update for all entities, then draw for all entities, repeatidly).
This will maybe give you an idea, i 'mark' my entities with properties ( amIBomb ) and then in the Game.Update i search for those having this property set to interact in another way with those entities. OR you can use instanceof operator to know which entity 'class' you're dealing with. Obviously using a flag property is faster and more flexible.
1 decade ago
by Joncom
ig.module('game.entities.example')
.requires('impact.entity')
.defines(function() {
EntityExample = ig.Entity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
},
update: function() {
if (ig.input.pressed('somekey') {
var thisEntity = this;
// Call whatever method you'd like.
// And pass in this entity so that yourMethod
// knows which entity called it.
ig.game.yourMethod(thisEntity);
}
}
});
});
Page 1 of 1
« first
« previous
next ›
last »