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 Gary

Hello all!

I'm new to Impact and game development. I'm not new to JS, but I'm no expert either.
So before I ask my question, I just have to say I've been playing with Impact for a few weekends and I'm simply astounded at how powerful it is and how easy it makes game development. I'm having all kinds of fun over here!!

That said, I'm a bit stuck on something I think should be pretty easy...
I want to spawn a couple of entities in the init function of my game, after the level has been loaded. However, I want to base the start position of these entities on the size of the entities themselves... Basically I'm trying to centre an entity on the screen, thus:

ig.game.spawnEntity(EntityBat, (ig.system.width / 2) - (EntityBat.size.x / 2), 100);

Note that I don't expect the above code to work, I'm just trying to illustrate what I'd like to do.
What I need is access to the properties of the 'Bat' entity, but before the entity is instantiated, so that I can pass the correct position to the spawnEntity function.

This is basically for future proofing, I could specify the starting position manually, or I could spawn the entity and update the position immediately - but this method would allow me to arbitrarily change the size of the entity and screen without updating code.

Does this sound like something I should be able to do? Or is there a better way of doing it?

1 decade ago by jerev

If you don't want initiation, you could place the size property outside of the entity.extend, like this:
EntityBat = ig.Entity.extend({
    ...
});

EntityBat.size = {
    x: 8,
    y: 8
}

And now you'll have access to the size property without initiation - and it should all still work.

1 decade ago by dominic

This gets the default properties without instantiating a Class:
EntityBat.prototype.size.x;

1 decade ago by jerev

Quote from dominic
This gets the default properties without instantiating a Class:
##
EntityBat.prototype.size.x;
##


Oh ye.. of course :D
Page 1 of 1
« first « previous next › last »