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 Dhoombaby

Hello,
i am new to impactjs...i have read books of html5 game development. but at some point i couldn't understand the logic. In jumpnrun game below is some code for enemy. If he is near an edge then reverse the direction...but i am not getting what this code exactly does??? can anyone help me to understand it ??



if( !ig.game.collisionMap.getTile(
this.pos.x + (this.flip ? +4 : this.size.x -4),
this.pos.y + this.size.y+1
)
) {
console.log('in if....');
this.flip = !this.flip;

// We have to move the offset.x around a bit when going
// in reverse direction, otherwise the blob's hitbox will
// be at the tail end.
this.offset.x = this.flip ? 0 : 24;
}

1 decade ago by stillen

// We have to move the offset.x around a bit when going
// in reverse direction, otherwise the blob's hitbox will
// be at the tail end.

The offset is like the hit box. Since the animation is flipped, you have to move the hit box accordingly.

If you turn the debugging option on you can see the offsets of each entity. That may make it easier to understand
Page 1 of 1
« first « previous next › last »