Search code examples
androidtextcenterdrawgame-maker

How to draw a text in center on Android (Game Maker Studio)


I am trying to draw score in center after game end. It is in center on windows but not on Android. I have 800*480 room and tested game on Galaxy S III . The text is like in 200*120 on Galaxy S III.

I tried these codes:

draw_text(global.width/2,(global.height/2),score)

.

draw_text(room_width/2,room_height/2,score)

.

draw_set_halign ( fa_center );
draw_set_valign ( fa_middle );
draw_text(view_xview[0]+view_wview[0]0/2,(view_yview[0]+view_hview[0]/2),score);

And doesn't work.

I'm struggling this problem for many hours. Im going to go nuts :pirate:

Thanks for your reply !


Solution

  • I don't have all the necessary information, but it sounds to me like you might be calling this code using the Draw GUI event. If so, then solving the problem is as simple as just moving the draw code into the Draw event.

    The standard draw event will draw onto the screen surface, and the text will get scaled along with the rest of your graphics. If you do not what this scaling, you can still use the Draw GUI event, but you'll need to position your text differently.

    Off the top of my head, I am thinking this should do the trick:

    if (os_type == os_android) {
      draw_text(display_get_width() / 2, display_get_height() / 2, score);
    } else if (os_type == os_windows) {
      draw_text(room_width / 2, room_height / 2, score);
    }
    

    The only thing to be wary of is that this will position the text the same as it does in Windows, but it will not scale the text the same way. Unfortunately until GM:S 1.3 is available with TrueType font support (coming soon as of this writing) you can't really do much about this short of adding lots of different size font and selecting them based on the size of the screen (which again you can get through display_get_width() and display_get_height())