View to GUI Conversion

Credit: Gizmo199

function view_to_gui_x(camera, x)
	return ((x - camera_get_view_x(camera)) / camera_get_view_width(camera)) * display_get_gui_width();

function view_to_gui_y(camera, y)
	return ((y - camera_get_view_y(camera)) / camera_get_view_height(camera)) * display_get_gui_height();


These are simple scripts that convert the given x/y coordinates in a room to the appropriate x/y coordinates on the GUI layer when using views. These scripts are essential, especially when dealing with shader effects that need to be drawn on the GUI layer (eg. Motion blur, Shockwaves, etc.). They are also particularly good for rendering elements such as text boxes or input prompts to the screen on the GUI layer where needed.

Optimization Tip

#macro inline gml_pragma("forceinline")

Add this somewhere in your game, and you will be able to simply type inline; in a function to make it faster to call in YYC mode. I would personally always inline simple helper functions like the two listed above.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s