No, what I was saying is that when I tried to use an offset, it moved the IMAGE too so that it was rendering 20 pixels up from the actual position which is what is causing confusion. So, does it mean that it's not possible to move a collision box via an offset without also moving the image itself?
These screenshots might explain better (ignore the bomb and key, they are positioned at random) my problem.
Without an offset, the red 'arrow heads' render correctly, inside the grid square.
1 decade ago
by stillen
Can you post more of your code, b/c offset shouldn't move the image only the collision box. I have used this on a lot of my games.
Perhaps you somewhere the pos.x and the offset.x are getting set incorrectly?
1 decade ago
by anthony
Yeah sure. I've gone through all the code related to this and here it is.
Here's how I spawn the objects:
// this is in main...
// TILE_WIDTH = 40
// TILE_HEIGHT = 44
// ...
this.spawnEntity(EntityDeflector, 2 * this.TILE_WIDTH, 5 * this.TILE_HEIGHT, {direction:this.FACING.UP});
this.spawnEntity(EntityDeflector, 2 * this.TILE_WIDTH, 6 * this.TILE_HEIGHT, {direction:this.FACING.RIGHT});
And here's the variables and init function:
// the init function of the object
EntityDeflector = ig.Entity.extend({
size : {x:20, y:22},
offset: {x:10, y:11}, // as per dominic's suggestion
animSheet: new ig.AnimationSheet('media/img/object/deflector.png', 40, 44),
// .. chopped out non-relevant variables...
init: function(x, y, settings) {
this.parent(x, y, settings);
this.addAnim('idle', 0.5, [0]);
this.currentAnim = this.anims['idle'];
this.deflectSound = new ig.Sound('media/snd/deflector.*');
this.direction = settings.direction;
this.collided = false;
// faces up by default.
if (this.direction === ig.game.FACING.DOWN) {
// DOWN
this.currentAnim.angle = (-1.5707 * 2);
}
else if (this.direction === ig.game.FACING.LEFT) {
// LEFT
this.currentAnim.angle = -1.5707;
}
else if (this.direction === ig.game.FACING.RIGHT) {
// RIGHT
this.currentAnim.angle = 1.5707;
}
},
//... there are no other changes to pos, size, offset, etc made
// in the rest of the code as these are static objects.
draw: function() {
this.parent();
}
1 decade ago
by stillen
I've never used the currentAnim.angle. Does the offset work properly without the angle adjustment?
1 decade ago
by anthony
The upward facing deflector does not have any angle of rotation applied to it as the image faces up by default and it is still affected by applying the offset.
I've been able to get around the problem by writing specific x and y checks in the EntityDeflector's check() function and not using any offset as I was getting quite bogged down with this issue.
I'll come back to this at a later date to tackle it and if there's any update I'll post a reply here.
Thanks Joncom, dominic and stillen for your replies :)
Page 1 of 1
« first
« previous
next ›
last »