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 PabloAM

Hello everyone.

I´m having a problem with spawnEntity and how spawn Entities from a class.

The thing is that I have a Class named "Life" and I want to do a generic class called "TextInfo".

The purpose is do a spawnEntity of TextInfo from Life with a text wrote.

If I write the code in the same file works.
If I create a InfoText.js doesn´t works.

Which could be the problem?

The code (brief):
///////////////////////
Life.js:
/////////////////////////////
 check: function( other ) {
                if (other instanceof EntityPlayer && !this.touched) {
                    this.lifeUpSFX.play();

                    ig.game.lives ++;

                    ig.game.spawnEntity( EntityInfoText ,this.pos.x, this.pos.y );
}

////////////////////////
InfoText.js:
//////////////////////////

ig.module(
    'game.entities.InfoText'
)
.requires(
    'impact.entity'
)
.defines(function(){
    EntityInfoText = ig.Entity.extend({

     //MY CODEEE...

});

1 decade ago by StuartTresadern

Missing a reference in life.js .requires to InfoText.js ?

What does you debug console say ?

1 decade ago by PabloAM

Thanks! , now is working but I have another question.
Why this works without write the require ?

ig.module(
    'game.entities.gun'
)
    .requires(
    'impact.entity'
)
    .defines(function(){
        EntityGun = ig.Entity.extend({
            size: {x: 5, y: 3},
            animSheet: new ig.AnimationSheet( 'media/bullet.png', 5, 3 ),
            maxVel: {x: 200, y: 0},
            type: ig.Entity.TYPE.NONE,
            checkAgainst: ig.Entity.TYPE.B,
            collides: ig.Entity.COLLIDES.PASSIVE,
            init: function( x, y, settings ) {
                this.parent( x + (settings.flip ? -4 : 8) , y+8, settings );
                this.vel.x = this.accel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
                this.addAnim( 'idle', 0.2, [0] );
            },
            handleMovementTrace: function( res ) {
                this.parent( res );
                if( res.collision.x || res.collision.y ){
                    this.kill();
                }
            },
            check: function( other ) {
                other.receiveDamage( 5, this );
                this.kill();
            }
        });
 });

Player.js

ig.module(
  'game.entities.player'
)
.requires(
    'impact.entity',
    'impact.sound'
)
.defines(function(){
   EntityPlayer = ig.Entity.extend({
//// SOME CODE

   if( ig.input.pressed('buttonShoot') ) {
               ig.game.spawnEntity( this.activeWeapon, this.pos.x, this.pos.y, {flip:this.flip} );
               this.shootSFX.play();
           }

1 decade ago by StuartTresadern

I can't tell from the code you have posted !, does the main.js already have a ref to the gun entity ?

1 decade ago by PabloAM

The main.js has this:
ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font',
    'game.levels.level1',
    'impact.timer'
    //'impact.debug.debug'
)

Maybe is because the 'impact.game' ?

Thanks again!

1 decade ago by StuartTresadern

No, I can not see what this.activeWeapon is from the code above if you post the full code I may be able to explain whats going on.
Page 1 of 1
« first « previous next › last »