GML [1.4.9999] wrong view showing

woods

Member
i have two views in my space shooter game.. view [0] on the left for P1 and view[1] on the right for P2

i am trying to draw HP to GUI layer with a control object in the top right corner of each view.

obj_control draw GUI event
Code:
/// draw my health


//draw_text(view_xview[0] + 32, view_yview[0] + 32, "HP: " + string(obj_P1.HP));
//draw_text(view_xview[1] + 32, view_yview[1] + 32, "HP: " + string(obj_P2.HP));

draw_text(view_xview[0] + 64, view_yview[0],"view " + string(view_current)); // debug show current view -looking for view[0]
draw_text(view_xview[1] + 64, view_yview[1],"view " + string(view_current)); // debug show current view -looking for view[1]

if (room = rm_play)
{
    if (view_current == 0)
    {   
        draw_text_transformed(view_xview[0], view_yview[0], "health " + string(obj_P1.HP),2,2,0); // draw P1 HP
    }

    if (view_current == 1)
    {   
        draw_text_transformed(view_xview[1], view_yview[1], "health " + string(obj_P2.HP),2,2,0); // draw P2 HP
    }
}
the debug text shows up floating around the player ship when i get NEAR the top corner of the room.. both ships show current view: 7
nowhere have i even touched or referenced view 7 ...i only have view 0 and 1 selected in my game.(left and right player screens)



my question is this:
how do i draw basic player HP in the corner of thier respective views?


edit:
after 6 hours i realized my code was in the draw GUI event instead of the regular DRAW event
(fixed)
 
Last edited:

woods

Member
yeah.. that really screwed me up for a minute.
draw text current_view:7 was sliding all over the place on both screens in relation to the ships...
it took me a bit then i realized the text was holding still like it should.. the illusion was the view and the ship were moving. the text was holding still on the GUI layer like i told it to.
the bit that threw me off was view 7 ... like wtf? hahaha
 
I don't think the GUI is view 7 as you can have view 0 - 7. I suspect that the problem is that the view_current is supposed to be used from the Draw Event not the Draw GUI, and what probably happens is that all the views are cycled through to determine whether it should be drawn to or not, and as the Draw GUI would happen afterwards the last view has been checked that last view would have been #7 so view_current would still hold 7 as the value until the next Draw cycle starts (when it would go back to 0 again).
If the code had been done in the Draw Event, I think you would see different behaviour.
 
Top