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 Jon

Hello all,

I am trying to find a way to create multiple images of a ball inside of one entity. Each image may be different sizes from one another. After hitting this entity with my game's bullets...I need a way to determine which of the balls were actually struck.

I was originally planning on creating one entity that creates the image itself (lets call this EntityImageCreate) and another entity that will call this create multiple times (lets call this EntityImageCombine). This will ensure that each of these balls are part of the same Combine entity. However, I am receiving the following error when it calls the spawnEntity of the Create:

uncaught exception: Can't spawn entity of type imagecreate

Here is EntityImageCombine:
ig.module(
    'game.entities.imagecombine'
)
    .requires(
    'impact.entity',
    'game.entities.enemy'
)
.defines (function(){
    EntityImageCombine = EntityEnemy.extend({
        size: { x: 8, y: 14},
        init: function (x, y, settings){
            this.parent( x, y, settings );
            this.generate();
            this.lastAttackTimer = new ig.Timer();
        },
        generate: function() {
            ball1= ig.game.spawnEntity('imagecreate',18,18),  <---------The error is occurring here
            ball2= ig.game.spawnEntity('imagecreate',18,18)
        }
    });

Here is EntityImageCreate:
ig.module(
    'game.entities.imagecreate'
)
    .requires(
    'impact.entity',
    'game.entities.enemy'
)
    .defines (function(){
    EntityImageCreate = EntityEnemy.extend({
        animSheet: new ig.AnimationSheet( 'media/web/ammo/ball.png', 18, 18),
        size: { x: 8, y: 14},
        offset: {x: 4, y:2},
        maxVel: {x: 100, y: 100},
        speed: 140,
        init: function (x, y, settings){
            this.parent( x, y, settings );
            this.addAnim( 'idle', 1, [0]);
            this.lastAttackTimer = new ig.Timer();
        }
    });
});

Does anyone see my issue? Or perhaps have a better suggestion on how to accomplish my goal?

Thanks!

1 decade ago by Jerczu

Check my modular entity I think I have bits of code there that might interest you http://impactjs.com/forums/code/modular-entity

1 decade ago by Joncom

Quote from Jon
I need a way to determine which of the balls were actually struck

If you need to run collisions on individual balls, it may make more sense to make each ball it's own entity. And if you want the ball entities to act as if they are part of a greater whole, you could simply position them relative to a 'parent' entity.

To do so, just make sure that when you spawn each ball, you pass the parent entity in, like so:

// Spawn parent.
var parentEntity = ig.game.spawnEntity(EntityParent, 0, 0);

// Spawn ball(s).
for(var i=0; i<3; i++) { 
    ig.game.spawnEntity(EntityBall, 0, 0, { parentEntity: parentEntity });
}

And then inside of your ball entities:
update: function() {

    // Set position to be same as the parent.    
    this.pos = this.parentEntity.pos;

    // You can add and subtract a little from each ball so they don't stack
    // perfectly on top of one another.

    // Call parent (important, but has nothing to do with parentEntity).
    this.parent();
}
Page 1 of 1
« first « previous next › last »