• 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!

GML Can anyone explain why my icon in the bottom left keeps moving whever my camera moves?

B

bruhmoment.wav

Guest
This is the code I used to assign the position of the object:
GML:
if oPlayer.holdingItem = 1 {
    image_alpha = 100;
    if oPlayer.heldItem = "oSword" {
        sprite_index = sSword;
    }
}

if oPlayer.holdingItem = 0 {
    image_alpha = 0;
}

vx = camera_get_view_x(view_camera[0])+16
vy = camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0])-16
x = vx
y = vy

image_xscale = 2; image_yscale = 2;
The object somehow seems to be moving at the same speed the player is moving. But I have no idea how that connection came to be.
 

Attachments

woods

Member
looks like to me you are drawing in relation to the view...

this kinda acts similar to drawing to the hud


Code:
vx = camera_get_view_x(view_camera[0])+16
vy = camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0])-16
x = vx
y = vy
 

NightFrost

Member
I assume poorly phrased question. The sword is following the camera because you are reading camera position, but I think that's your intent. The bug I suppose is how the sword shakes around as you move. This is likely because the position is being calculated before camera is moved, so it lags one step behind. UI elements are best drawn in the draw GUI event, so they are always relative to camera.
 
Top