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

Discussion in 'Legacy GameMaker Community Tech Support' started by Sorry_For_Dumb_Questions, Nov 24, 2018.

  1. Sorry_For_Dumb_Questions

    Sorry_For_Dumb_Questions Member

    Joined:
    Nov 24, 2018
    Posts:
    22
    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?
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,164
    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.
     
  3. Sorry_For_Dumb_Questions

    Sorry_For_Dumb_Questions Member

    Joined:
    Nov 24, 2018
    Posts:
    22
    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 :/
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,769
    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?
     
  5. Sorry_For_Dumb_Questions

    Sorry_For_Dumb_Questions Member

    Joined:
    Nov 24, 2018
    Posts:
    22
    You are right, sorry, im newbie here :/
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice