• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED How can I offset an object by half a pixel?

Zabicka

Member
Hello, i'm trying to offset a bullet object to the center of my player (My game is very low res, so the center of my player object is 2 pixels wide)
and I'm not sure how to do it, I tried lengthdir_x and lengthdir_y but that doesn't work,
then I tried this x+0.5, y+0.5, but that doesn't work neither, because my player object rotates, any ideas?
 

Zabicka

Member
How did you implement the lengthdirs? That's going to be your solution, so post what you tried.
I tried this:
Code:
var _x = x + lengthdir_x(0.5, dir);
var _y = y + lengthdir_y(0.5, dir);

with (instance_create_layer(_x, _y, layer, obj_bullet)) {
      speed = 6;
      direction = other.dir;
      image_angle = direction;
}
Then I tried this:
Code:
with (instance_create_layer(x+0.5, y+0.5, layer, obj_bullet)) {
      speed = 6;
      direction = other.dir;
      image_angle = direction;
}
And I also tried this:
Code:
var _x = x + lengthdir_x(0.5, dir);
var _y = y + lengthdir_y(0.5, dir);

with (instance_create_layer(_x+0.5, _y+0.5, layer, obj_bullet)) {
      speed = 6;
      direction = other.dir;
      image_angle = direction;
}
 

Sabnock

Member
when you say offset half a pixel do you mean actually offset a pixel so you have 1 pixel overlapping 2?

that is not physically possible.

can you make your character 3 pixels wide?
 
Last edited:

Zabicka

Member
when you say offset half a pixel do you mean actually offset a pixel so you have 1 pixel overlapping 2?

that is not physically possible.

can you make your character 3 pixels wide?
I solved it. :)
Here is the code:
Code:
        var _value = 0.5;
        var _dir = point_direction(0, 0, _value, _value);
        var _dis = point_distance(0, 0, _value, _value);
    
        var _x = x - lengthdir_x(_dis, _dir + dir);
        var _y = y - lengthdir_y(_dis, _dir + dir);
    
        with (instance_create_layer(_x, _y, layer, obj_bullet)) {
            speed            = other.shot_speed;
            direction       = other.dir;
            image_angle = direction;
        }
 

TheouAegis

Member
Well, other than _dir always being 45, and _dis being sqrt(.5), so you could remove that part, glad you figured out a solution.
 
Top