• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

[SOLVED] When screen moving, view_xview object moves little bit

  • Thread starter Sorry_For_Dumb_Questions
  • Start date
S

Sorry_For_Dumb_Questions

Guest
I couldn't figure out why :/

here is 2 object i used;

objplayer : camera follows him
objhealthbar : an image i want to see always screen's 100,100 position (not room coordinate, view's 100,100 coordinate i mean)

The problem : when objplayer (and screen) moves, objhealthbar moves little bit like 100,100 -> 105,105



//// THE CODES /////


#### objplayer . CREATE EVENT
view_camera[0] = camera_create_view(0,0,1920,1080,0,objplayer,-1,-1,100,100);


#### objplayer . STEP EVENT
switch keyboard_key
{
case vk_left : x -= 10; break;
case vk_right : x += 10; break;
case vk_up : y -= 10; break;
case vk_down : y += 10; break;
}

----------------------------------------------------------------------------------------------------

##### objhealthbar . STEP EVENT
x = camera_get_view_x(view_camera[0]) + 100;
y = camera_get_view_y(view_camera[0]) + 100;


how can i fix this?
 

Simon Gust

Member
The reason this happens is because your healthbar object updates it's position before the camera does, so at the end of a step, the camera always escapes.

I have no idea when the camera is updated. Try putting the code in the draw event.

OR

don't update the healthbar positions at all. You can just draw the healthbar stuff manually in the draw GUI event.
Might as well draw it in the draw GUI event of the player.
 
S

Sorry_For_Dumb_Questions

Guest
The reason this happens is because your healthbar object updates it's position before the camera does, so at the end of a step, the camera always escapes.

I have no idea when the camera is updated. Try putting the code in the draw event.

OR

don't update the healthbar positions at all. You can just draw the healthbar stuff manually in the draw GUI event.
Might as well draw it in the draw GUI event of the player.
First of all, thank you for the answer ^^

Actually drawing healthbar just for an easy example, it wasnt my point in game.
I was trying to make virtual joystick (object based) but when screen moving, obj_joystick is moves too as like healthbar example.
I fixed it with GUI but im still wondering how to deal above example :/
 
S

Sorry_For_Dumb_Questions

Guest
You could try moving it to the Pre-Draw event. If that doesn't work, then the Begin Draw event.

By the way, isn't this a GMS2 question, not a Legacy question?
You are right, sorry, im newbie here :/
 
Top