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 doobdargent

Hi,
I just acquired ImpactJS and I love it!

I'm building a Shoot-em-up and because that kind of games use lots of entities, I built a simple BulletManager that return entities that can be re-used. (I was surprised that no plugins of this kind exists)

ig.module(
    'game.bulletManager'
)
.requires(
    'impact.entity',
    'game.entities.bullet'
)
.defines(function(){
    BulletManager = ig.Class.extend({

        bullets: [],
        outOfScreen: {x: -9999, y: -9999},

        init: function(cacheSize){
            this.bullets = new Array(cacheSize);

            for(var i=0; i<this.bullets.length; i++){
                this.bullets[i] = ig.game.spawnEntity(EntityBullet, this.outOfScreen.x, this.outOfScreen.y);
            }
        },

        getAvailable: function(){
            for(var i=0; i<this.bullets.length; i++){
                if(this.bullets[i].isInactive()){
                    return this.bullets[i];
                }
            }
            return null; // Send Exception
        }
    });
});

It's working. EntityBullets are created at init and I can use getAvailable() when needed.
The thing is the update() and draw() (maybe more) methods from the EntityBullets aren't called. I guess that's because Impact didn't add them to the ig.game.entities or something...

Any insight?
Cheers!

1 decade ago by mLautz

I've always initialized my entities with:

init: function(x, y, settings){
      this.parent(x, y, settings);
      // custom code here
}

Without the call to the parent function, the entity may not be registered with the main game. This may not be an issue for your manager, but if you do not call the parent function in the EntityBullet that is probably why they are not registering with your game. (That's my guess at least)

1 decade ago by doobdargent

Thanks for your reply mLautz.
The BulletManager is not an Entity, it's just a class.

But I just found the solution, it had nothing to do with my class. It was because I created the bulletManager (and the entities) before the loadLevel() method in my main.js.

I guess loadLevel() must clear the entities list.

If some people are interested, I'll improve that class and make a plugin, let me know ;)
Cheers!

1 decade ago by doobdargent

ah, sorry I misread your message. EntityBullet was fine. I had tried to spawn the EntityBullet without the manager and it was working fine.

1 decade ago by mLautz

And I misread your bulletManager class. Haha.

I should have thought to recommend checking that you loaded the level first! I've had a couple different issues with the exact same thing over the past two weeks.

1 decade ago by fulvio

Good luck with the plugin @doobdargent.

I'd be interested in seeing how it progresses. Once you finish it I'd recommend submitting it to http://www.pointofimpactjs.com/ if you haven't already.
Page 1 of 1
« first « previous next › last »