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 fulvio

Below you will see my wonderful laser beam:

ig.module('game.entities.laser-beam').requires('impact.entity').defines(function() {
    EntityLaserBeam = ig.Entity.extend({
        size: {
            x: 16,
            y: 16
        },
        offset: {
            x: 0,
            y: 0
        },
        _wmIgnore: true,
        type: ig.Entity.TYPE.B,
        checkAgainst: ig.Entity.TYPE.A,
        collides: ig.Entity.COLLIDES.NEVER,
        gravityFactor: 0,
        doorHeight: 1,
        lastTile: null,
        animSheet: new ig.AnimationSheet('media/sprites/laser-anim.png', 16, 16),
        canKill: null,
        init: function(x, y, settings) {
            this.parent(x, y, settings);
            this.animSheet = new ig.AnimationSheet('media/sprites/laser-anim.png', 16, this.doorHeight);
            this.size.y = this.doorHeight;
            this.addAnim('idle', 0.1, [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 1, 1, 1, 1]);
        },
        check: function(other) {
            if (this.canKill) {
                other.receiveDamage(ig.game.player.maxHealth, this);
            }
        },
        update: function() {
            if (this.currentAnim.frame == 0 || this.currentAnim.frame == 1) {
                this.canKill = false;
            } else {
                this.collides = ig.Entity.COLLIDES.PASSIVE;
                this.canKill = true;
            }
            this.currentAnim.update();
        },
        receiveDamage: function(amount, from) {}
    });
});

The problem is that the condition to check for frame 0 or frame 1 is never reached. Basically those frames are when the laser is in its off state.

I've used this.currentAnim.frame checks before and never had a problem. Not sure what's so different about this particular entity.

1 decade ago by quidmonkey

Quote from fulvio
The problem is that the condition to check for frame 0 or frame 1 is never reached. Basically those frames are when the laser is in its off state.

So you're saying your .update() is never being run?

1 decade ago by TigerJ

 update: function() {
            if (this.currentAnim.frame == 0 || this.currentAnim.frame == 1) {
                this.canKill = false;
            } else {
                this.collides = ig.Entity.COLLIDES.PASSIVE;
                this.canKill = true;
            }
            this.currentAnim.update();
        },

shouldn't you have a this.parent(); in that update extension? maybe I am wrong..

 update: function() {
            if (this.currentAnim.frame == 0 || this.currentAnim.frame == 1) {
                this.canKill = false;
            } else {
                this.collides = ig.Entity.COLLIDES.PASSIVE;
                this.canKill = true;
            }
            this.currentAnim.update();
            this.parent();
        },

1 decade ago by fulvio

Nope, update() is running just fine, however the condition to check for frame 0 or frame 1 is never met.

Even though the animation might be within frame 0 or 1 my player is still killed so therefore this.canKill is never set to false.

1 decade ago by TigerJ

Here is from the stream

EntityShot = ig.Entity.extend({
	size: {x: 1, y: 1},
	animSheet: new ig.AnimationSheet( 'media/bullet.png', 1, 1 ),
    type: ig.Entity.TYPE.A, // good
	collides: ig.Entity.COLLIDES.PASSIVE,
	checkAgainst: ig.Entity.TYPE.BOTH,
	gravityFactor: 0,
    shotTimer:null,
    shotCounter:null,
    canKill:null,
	init: function( x, y, settings ) {
        ig.game.laser1Sound.play();
        this.addAnim( 'idle', 1, [0,1,2] );
		this.parent( x, y, settings );
        protag = ig.game.getEntitiesByType(EntityProtag)[0];
        if(protag.currentGun==0 && !protag.guns.LongGun)
        {
            this.shotTimer = new ig.Timer(.3);
        }
        else if(protag.currentGun==0 && protag.guns.LongGun)
        {
            this.shotTimer = new ig.Timer(1);
        }
	},
	update: function(){
		 if (this.currentAnim.frame == 0 || this.currentAnim.frame == 1) {
            this.canKill = false;
        } else {
            this.collides = ig.Entity.COLLIDES.PASSIVE;
            this.canKill = true;
        }
        this.currentAnim.update();
		/*if(this.shotTimer.delta()>0)
        {
            this.kill();
        }*/
        //this.parent();
        console.log(this.canKill);
	},
	check: function(other){
		//console.log(other);
		if (this.canKill) {
				console.log(this.canKill);
                other.receiveDamage(ig.game.player.maxHealth, this);
            }
		/*
        if(other.name=='door')
        {
            if(other.openDoor==false && other.openTimer==null)
            {
                other.openDoor=true;
            }
            this.kill();
        }
		if(other.name!='protag')
		{
			this.kill();
		}
        if(other.name=='poopoo')
        {
            other.explode=true;
        }
        if(other.isEnemy)
        {
            other.explode=true;
        }*/
	},
	receiveDamage: function(amount, from) {},
	handleMovementTrace: function(res)
	{
        
		if(res.collision.x||res.collision.y)
		{
			this.kill();
		}
		this.parent(res);
	}
});

1 decade ago by fulvio

Hmm, looks like you lowered the animation time to 1 from 0.1.

Unfortunately I can't do the same as that would make my laser beam animation look very sluggish.

Even if I do change it to 1 from 0.1 my player still does every time.

I've spent hours on this and cannot figure out why.

1 decade ago by TigerJ

add more frames like
[0,1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

This would keep your animation time at .01 or whatever it is at, but extend the amount of time that the beam was in a no kill state.

so if your time is .01 and you want 2 seconds of movement you would need ALOT of 0,0,0,0,0 frames to flll up that time span.

A better approach now that I have slept may be to rethink the mechanic a little. Instead of using the animation frame to drive the beams killing, maybe an instance of ig.Timer() would be better.
this.canKillTimer = new ig.Timer(2);
if(this.canKillTimer.delta()>0)
{
  this.currentAnim.update();
  this.canKill=true;
  this.canKillTimer = new ig.Timer(2);
}
else
{
  this.currentAnim = this.anims.idle.rewind();
  this.canKill=false;
}

I have had no coffee yet this morning. I may think of something more later on if I get time. I have a big deadline today at the office job I'll be around later this evening again. good luck.

1 decade ago by mglnunez

if (this.currentAnim.frame == 0 || this.currentAnim.frame == 1) 

Only checks the first 2 frames of that animation resulting in only 0.2 seconds of not dying in those ~5 seconds.

Looks like you are confusing the current frame in the animation and the numbering of the frames in the animation sheet.
If this is true you would need to change it to...
if (this.currentAnim.frame < 21 || this.currentAnim.frame > 50)
// I might have miscounted 

I recommend splitting up that animation into smaller animations and using .loopCount to check how many times any given animation has looped. This will mostly help if you decide to change stuff later on.

1 decade ago by quidmonkey

Do this:
var frame = this.currentAnim.sequence[ this.currentAnim.frame ];
if( frame === 0 || frame === 1 ){
//kill
}
else{
//no kill
}

1 decade ago by alexandre

IIRC animations have a tile property that you can use like this:
this.canKill = (this.currentAnim.tile == 0 || this.currentAnim.tile == 1);

1 decade ago by fulvio

@TigerJ - Thank you!
@mglnunez - Thank you!
@quidmonkey - Thank you!
@alexandre - Thank you!

I will give all of these recommendations/fixes a shot and get back to you.

I ended up just going with this.canKill = (this.currentAnim.tile == 0 || this.currentAnim.tile == 1);. Thanks again everyone.
Page 1 of 1
« first « previous next › last »