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 dahl

My entity needs to "call" another entity to the board.

--spawnEntity just creates one, best i can tell.

i need the operator/function that actually brings an entity from the entities folder.

any help would be great! thanks.

1 decade ago by Jerczu

spawnEntity is the way to go.

1 decade ago by dahl

as far as i can tell Jerczu it won't spawn the "actual" entity i'm asking for. it's either blank, or if i add the anim code, it turns my "spawning" entity into a graphic of itself. i'll keep looking for the correct syntax though. thanks for the help.

1 decade ago by Jerczu

Hmmm... I'm having a difficulty in understanding what you are trying to achieve.

If spawn doesnt work then there must be a bug somewhere in your code. Try add this entity through weltmeister and check if it works ok on its own not spawned by other entity. Also check the jump n run demo and have a look how the grenade is spawned. You can always create an invisible entity that will act like spawner.

1 decade ago by dahl

Ok, this is what i did. I created an invisible spawner to check for certain conditions, then perform as needed. Komodo throws no errors, and impact runs the game error free in my server, BUT, lol it refuses to summon the dang entity. these 5 entities will rest at the top of the board and drop skulls(gems) into columns as spaces become empty. they will also work in conjunction with the other 30 "killers" to kill skull combos as they happen. Here the code.....

ig.module (
    'game.entities.b1'
)
.requires (
    'impact.entity'
    
)
.defines (function() {
    
    EntityB1 = ig.Entity.extend ( {
        size: { x:20, y:20},
        //this.pos.x =        // to be set later after testing
        //this.pos.y =
        collides: ig.Entity.COLLIDES.FIXED,
        type: ig.Entity.TYPE.B,
        checkAgainst: ig.Entity.TYPE.A,
        _wmDrawBox: 'true',
        _wmBoxColor: 'rgba( 255, 0, 0, 0.5 )',
        
       
        
     init: function() {
        
        // mouse/touch code to go here.
        
    },                  
    
    update: function() {
        
        var skull = [];
        var attack = 'false';
        var spawn = '1';
        
        this.parent();
        
        },
    
    check: function ( other ) {
        
        if(other.standing == 'true') {
            if(this.touches(other instanceof EntityPuck)) {
                this.skull = [R]
            } else
            if(this.touches(other instanceof EntityGreenskull)){
               this.skull = [G]
           } else
            if(this.touches(other instanceof EntityBlueskull)) {
                this.skull = [B]
            } else
            if(this.touches(other instanceof EntityYellowskull)) {
                this.skull = [Y]
           } else
            if(this.touches(other instanceof EntityOrangeskull)) {
               this.skull = [O]
           } else
            if(this.touches(other instanceof EntityPurpleskull)) {
               this.skull = [P]
            } else
            if(this.touches(other instanceof EntityWhiteskull)) {
                this.skull = [W]
            }
            
        };  
          
            if(this.attack == 'true') {
                kill( other ) // add score code here....
            }
            
        
       
       // B6 - B35 end here.
        // spawning code, B1 - B5 ONLY
       this.spawn = rand( 1, 7 );  // commented out to test case '1'
        switch (spawn) {
            case '1':
                ig.game.spawnEntity( EntityPuck, 32, 0 ); // 'puck == Redskull for testing
                this.spawn = 0;
                break;
            case '2':
                ig.game.spawnEntity(EntityBlueskull, this);
                this.spawn = 0;
                break;
            case '3':
                ig.game.spawnEntity(EntityGreenkull, this);
                this.spawn = 0;
                break;
            case '4':
                ig.game.spawnEntity(EntityYellowkull, this);
                this.spawn = 0;
                break;
            case '5':
                ig.game.spawnEntity(EntityPurpleskull, this);
                this.spawn = 0;
                break;
            case '6':
                ig.game.spawnEntity(EntityOrangeskull, this);
                this.spawn = 0;
                break;
            case '7':
                ig.game.spawnEntity(EntityWhiteskull, this);
                this.spawn = 0;
                break;
        };
        
        
    },
});
});

i'm using the puck.js file slightly modded to use as a place holder for my graphic(still in process) code:

EntityPuck = ig.Entity.extend({
	
	size: {x:48, y:48},
	collides: ig.Entity.COLLIDES.FIXED,
	type: ig.Entity.TYPE.A,
	checkAgainst: ig.Entity.TYPE.A,
	
	animSheet: new ig.AnimationSheet( 'media/puck.png', 48, 48 ),
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		this.addAnim( 'idle', 0.1, [0,1,2,3,4,4,4,4,3,2,1] );
		
		this.vel.x = 0
		this.vel.y = 30
		
		
	},
	
	

});

});

vel.x is set to 0 so that it will fall straight down via gravity. otherwise it tries to move across the x axis.
like i said, i'm just not sure what i'm doing wrong. i get no exceptions thrown at me, it just won't give me the dang puck. lol.

thanks for your input thusfar, and i'm sure you're about to knock this one out the box.

1 decade ago by Jerczu

switch (spawn) 

you assign random number to this.spawn so it should be called like this?
//this should be
switch(this.spawn)

or is the spawn is a variable somewhere else?

1 decade ago by dahl

'spawn' is set in the update: function() section. but i changed it up like you suggested and it still won't spawn the entity. i'm not quite sure what i'm doin wrong. but i do appreciate all your help with it. thanks.
Page 1 of 1
« first « previous next › last »