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 was wondering if impact gives you a way to make modules that are just "behaviors" and add them to objects. Sort of like an object that is just full of functions that you can then "inject" into your entity. Can this be done in this way, or do I have to use standard inheritance? Can this be done dynamically?

Thanks,
-Xaan

1 decade ago by alexandre

Going for the plugin approach merits consideration; that would be my first option too, but only after I could clearly and unequivocally answer this question: do I really need to be able to modify impact's classes using an inject, knowing that every game has its own behaviour specification?

I have some doubts, but that's because I haven't yet felt the need for that, as opposed to direct subclassing.

1 decade ago by alexandre

For example, I am in the process of writing a RandomMovement plugin that inherits from Behaviour, a plugin that is simply embedded within my ig.Entity subclass, i.e., no injection but rather subclassing.

One reason I'd use injection would be for temporary modifications of existing classes, i.e., temp changes that do not disturb the current order, e.g., for debugging.

1 decade ago by gxxaxx

I have had great luck so far using subclassing for adding special behavior.

In the update method I implement whatever special behavior I want, then make a call to the parent update method (the one in ig.Entity) and let it do its magic.

In only one case was the behavior so special that I had to do it all in my subclass and not call the parent. But that is just the one case.

When it comes to implementing special behaviors I use a plugin which I then call from within the creature update. Something like the following.

	update: function() {
		if (this.splbehave) {
		     ig.game.Behaviors.moveme(this.splbehave,this);
		} else {
		     this.doMovement();
		}
		this.noLeaveMap();
		this.parent();
	},

Maybe I should use real injection. But since I'm new to javascript and don't grok the injection thing yet, I've avoided it.

In any case, with a little subclassing and a hacked together use of a plugin impactjs let's me do everything I need. AND, I can let impactjs do most of the heavy lifting.
Page 1 of 1
« first « previous next › last »