• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Query - Drawing to Camera/View - camera_get_active() vs. view_camera

Bulletech

Member
I was recently 'pulling my hair out' trying to figure out why my code for drawing a cursor (without mouse_x and mouse_y) to a camera view wasn't working... and I'm still not sure.

I was using functions like camera_get_view_x(camera_get_active()); as suggested in a YT video I found "Using and Drawing With Views in GameMaker Studio 2 Tutorial" and no matter what I did it wasn't working as expected, even though my debug to see what the function was returning seemed fine.

I then found view_camera[0...7] in the GameMaker Manual and tried camera_get_view_x(view_camera[0]); and so on instead and it worked with no issues. But I'm not sure as to why? I think it might've been an issue with switching between rooms with no cameras/views to a room with a camera/view?
 

Bulletech

Member
example code where view_camera[0] works, but camera_get_active() doesn't:

Code:
if (cursor_x < camera_get_view_x(view_camera[0]))
{cursor_x = camera_get_view_x(view_camera[0]);}
if (cursor_x > camera_get_view_x(view_camera[0])+camera_get_view_width(view_camera[0]))
{cursor_x = camera_get_view_x(view_camera[0])+camera_get_view_width(view_camera[0]);}
if (cursor_y < camera_get_view_y(view_camera[0]))
{cursor_y = camera_get_view_y(view_camera[0]);}
if (cursor_y > camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0]))
{cursor_y = camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0]);}
 

TheouAegis

Member
When you say it didn't work, do you mean it was drawing your cursor in all views rather than just one? All cameras are active every draw event; you have to check the id of the currently active one. By using view_camera, you are essentially limiting it to the particular camera.
 

Bulletech

Member
No not specific to drawing the cursor, more to do with checking where the cursor is, like the example code above
 

rIKmAN

Member
If you want a custom cursor use:
window_set_cursor(cr_none);
draw_sprite((CursorSprite),0,mouse_x,mouse_y);
The first line of OP says: "trying to figure out why my code for drawing a cursor (without mouse_x and mouse_y)"

This thread is also 9mths old.
 
Top