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 drhayes

This might be hard to explain and requires some screenshots. I'll do my best.

Weltmeister isn't drawing one of my entities correctly. I suspect it is because of the custom draw code.

I have an entity representing a gun with a barrel that can aim. I'm achieving this by defining the entity like this:

  EntityGun = ig.Entity.extend({
    
    animSheet: new ig.AnimationSheet('media/gun.png', 16, 16),
    
    size: {x: 16, y: 16},
    
    barrelAngle: 0,
    
    init: function(x, y, settings) {
      this.parent(x, y, settings);
      
      this.addAnim('base', 1, [0], true);
      this.addAnim('shoot', 0.05, [1, 2, 2, 3, 3, 3, 2, 2, 2, 1], true);
      this.anims.shoot.pivot = {x:2, y: 5};
      this.anims.shoot.frame = 9;
      
      this.currentAnim = this.anims.base;
    },
    
    setBarrelAngle: function(angle) {
      this.anims.shoot.angle = angle;
    },
    
    draw: function() {
      this.parent();
      this.anims.shoot.draw(this.pos.x + 6, this.pos.y - 3);
    },
    
    update: function() {
    }
  });

The important bit is the draw function. Notice how it calls the parent to draw the base and then draws the shoot animation on top of it, offset a bit.

This works great in the game itself.

In Weltmeister, once I move the map by right-click dragging, I start to see problems. Here's a screenshot of Weltmeister after I've right-click dragged down and to the right.

1 decade ago by drhayes

Whoops! Should have mentioned that when I drag the entity around the barrel moves around relative to the entity but still offset based on how much I've right-click dragged.

1 decade ago by dominic

I guess it only works in the game, because you don't move the screen there? You have to take the screen position into account, like so:

draw: function() {
	this.parent();
	this.anims.shoot.draw(
		this.pos.x + 6 - ig.game.screen.x, 
		this.pos.y - 3 - ig.game.screen.y
	);
},
Page 1 of 1
« first « previous next › last »