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 paulh

Hi all

Thanks for your continued help on the board id be completely stuck with you!

Id like to spawn an entity from a fixed position on the screen and not have it scroll with the scrolling map. Im using a fixed velocity on the player to scroll the map.

Im using the laser class from : http://impactjs.com/forums/help/drawing-a-laser-beam-effect

Currently i have the laser spawing but it scrolls of the map and will keep spawning (on button press) off the screen.

How would i make it so the laser is drawn from a fixed position on the screen to the mouse co-ordinates and the effect is "static" (not scrolling) on the screen.



ig.module("game.entities.laser").requires("impact.entity").defines(function() {
    EntityLaser = ig.Entity.extend({
        start: {},
        target: {},
 
        init: function(x, y, settings) {
          this.parent(x,y,settings);

          this.target.x = 300;
          this.target.y = 500;

          this.timer = new ig.Timer(0.25);
        },
 
        update: function() {
          if (this.timer.delta() >= 0) {
            this.kill();
          }

          this.parent();
        },

        draw: function() {
          var startX = ig.system.getDrawPos(this.pos.x - ig.game.screen.x);
          var startY = ig.system.getDrawPos(this.pos.y - ig.game.screen.y);
                
          var endX = ig.system.getDrawPos(this.target.x-ig.game.screen.x);
          var endY = ig.system.getDrawPos(this.target.y-ig.game.screen.y);
                
          ig.system.context.strokeStyle = "yellow";
        ig.system.context.lineWidth = 20;
          ig.system.context.beginPath();
          ig.system.context.moveTo(startX,startY);
          ig.system.context.lineTo(endX,endY);
          ig.system.context.stroke();
          ig.system.context.closePath();
        }
    });
});


##main.js
if( ig.input.pressed('shoot') ) {
ig.game.spawnEntity( EntityLaser, 200, 200 );
}

##
Also i noticed that my entities arent being killed when they exit on the left side of the screen, how do i kill them when they're off screen?

Many thanks

1 decade ago by paulh

:-)

Got the laser firing to a mouse location, is this right (tested and working)?

update: function() {
          if (this.timer.delta() >= 0) {
            this.kill();
          }
          if(ig.input.state("CanvasTouch"))
        {
            nY = ig.input.mouse.y;
            nX = ig.input.mouse.x;

        }

          this.parent();
        },

        draw: function() {
          var startX = 250;
          var startY = 50;
                
          var endX = nX;
          var endY = nY;


Now to kill entities!!

1 decade ago by paulh

:-(
Two steps forward, one step back ..

im guessing

        check: function( other ) {
		other.receiveDamage( 10, this );
		this.kill();
	}

wont work for the laser ? is there an easy fix?


ig.module("game.entities.laser").requires("impact.entity").defines(function() {
    EntityLaser = ig.Entity.extend({
        start: {},
        target: {},
 
        type: ig.Entity.TYPE.A, // Player friendly group
	checkAgainst: ig.Entity.TYPE.B,
	collides: ig.Entity.COLLIDES.PASSIVE,
        
        
        init: function(x, y, settings) {
          this.parent(x,y,settings);

          this.target.x = 300;
          this.target.y = 500;

          this.timer = new ig.Timer(0.25);
        },
 
        update: function() {
          if (this.timer.delta() >= 0) {
            this.kill();
          }
          if(ig.input.state("CanvasTouch")) {
            nY = ig.input.mouse.y;
            nX = ig.input.mouse.x;
          }

          this.parent();
        },

        draw: function() {
          var startX = 250;
          var startY = 50;
                
          var endX = nX;
          var endY = nY;
                
          ig.system.context.strokeStyle = "yellow";
          ig.system.context.lineWidth = 20;
          ig.system.context.beginPath();
          ig.system.context.moveTo(startX,startY);
          ig.system.context.lineTo(endX,endY);
          ig.system.context.stroke();
          ig.system.context.closePath();
        },
        
        check: function( other ) {
		other.receiveDamage( 10, this );
		this.kill();
	}
    });
});
Page 1 of 1
« first « previous next › last »