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 ShawnSwander

So for the most part coding isn't too hard for me but I'm having trouble spawning something into my game outside of the map editor. In the end I want a mouse click to trigger footprints showing the path to where you clicked. I finished the pathing code but I can't figure out how to make a footprint appear. Any help would be appreciated.
ig.module (
   'game.entities.path'
)

.requires(
   'impact.entity'
)

.defines(function(){
   var HEX_SIZE = 55;   
   EntityPath = ig.Entity.extend({
      size: {x: HEX_SIZE, y: HEX_SIZE},
      animSheet: new ig.AnimationSheet( 'media/path.png', HEX_SIZE, HEX_SIZE),
      zIndex:999,
      pos: {x: 220, y:220},
      
      init: function( x, y, settings ) {
         // Add the animations
      	 this.addAnim( 'bluenorth', 0.1, [0] );
         this.addAnim( 'bluenortheast', 0.1, [1] );
         this.addAnim( 'bluenorthwest', 0.1, [1] );
         this.addAnim( 'blueeast', 0.1, [2] );
         this.addAnim( 'bluewest', 0.1, [2] );
         this.addAnim( 'bluesoutheast', 0.1, [3] );
         this.addAnim( 'bluesouthwest', 0.1, [3] );
         this.addAnim( 'bluesouth', 0.1, [4] );
         //flip west facing animations
         this.anims.bluenorthwest.flip.x = true;
         this.anims.bluewest.flip.x = true;
         this.anims.bluesouthwest.flip.x = true;
         this.currentAnim = this.anims.bluenorth;
         
         this.parent( x, y, settings );
      },
      
      update: function(){
         var myEnt = new EntityPath( 220, 220);
         var myEnt2 = ig.game.getEntitiesByType( EntityPath )[0];
         ig.Game.spawnEntity(EntityPath,220,220);
         
        this.parent();
      },
   });
})


I tried putting the spawn in the init portion and it didn't work either.

1 decade ago by dominic

Use your browser's developer console. You should see an error message with your code.

Here&039;s why: #ig.Game is a class. The current instance of that class is at ig.game - lowercase 'g'. In fact, all class names in Impact are UpperCamelCase, while instance variables and primitives are lowerCamelCase.

This should work:
ig.game.spawnEntity( EntityPath, 220, 220);

1 decade ago by ShawnSwander

@dominic thanks

I did get it to work and part of the time I was using the big G and fixed it... I was having problems also because it wasn't in my main.js init function... is there a reason for that?

1 decade ago by dominic

What wasn&039;t in your main.js? #ig.game is accessible from anywhere in your code. As long as your game is running, you can spawn entities.

1 decade ago by ShawnSwander

@dominic I got an error when it was in the update function. It might be that you can't spawn something that is already spawned so I might need an if statement to make sure it doesn't already exist.

here is the error from my browser

Uncaught RangeError: Maximum call stack size exceeded
...
Class
ig.Game.ig.Class.extend.spawnEntity
ig.Entity.extend.init
window.ig.Class.extend.prototype.(anonymous function) <--- this repeats
Page 1 of 1
« first « previous next › last »