Camera movement and GUI problems

L

lolols...

Guest
so I'm creating a game right now and I've come across a slight problem with the camera movement. the code I'm using which is this seems to not work very well:
///Camera Movement
view_xview[0] += ((x-(view_wview[0]/2)) - view_xview[0]) * 0.5;
view_yview[0] += ((y-(view_hview[0]/2)) - view_yview[0]) * 0.5;
I would use the camera movement that's apart of the room editor but its not very smooth and my sprites are small so I guess that does not help. The problem I have with my current code is that it continues to show things that are past my room's boundaries. How do I fix this?

My second question is how do I implement a simple GUI into my game (which is a platformer by the way). The way I want to approach it is by having a scoreboard sprite at the bottom of the screen and it shows the player's lives and stuff but, I have little to no idea how to do this. Thank you in advance for anybody who's willing to help.
 

jo-thijs

Member
Hi and welcome to the GMC!

To fix the camera going beyond the edges of the room, use this instead:
view_xview[0] += clamp(((x-(view_wview[0]/2)) - view_xview[0]) * 0.5, 0, room_width - view_wview[0]);
view_yview[0] += clamp(((y-(view_hview[0]/2)) - view_yview[0]) * 0.5, 0, room_height - view_hview[0]);

To create a GUI, it is recommended to use the GUI draw event in some controller object.
You'd use draw_sprite(...) there to draw your GUI sprite on the bottom of the screen.
If you need more help with it, feel free to ask.
 

Misty

Member
Your code is probably solved, but just for future reference, it may be easier to create a camera object, and move the camera object, then set the view to the camera object directly, rather than using additive views and setting the views primarily as you are doing here.
 
L

lolols...

Guest
Ok I've implemented the code given and it works fine at first but I realized that it will not follow you if you go backwards so it acts sort of like the camera in super mario bros. which I was not going for. Instead I just wanted the player object to be shown everywhere it moves in the area inside the room and not show things outside of its boundaries.

as for the GUI well, I implemented my draw GUI event and it works... but the GUI / scoreboard is extremely tiny. I guess this is due to me magnifying everything with the room editor so the screen size is larger. I'll try fixing this and see where it leads

also if you need more info on my room's view its 160 by 144 and its magnified to 800 by 720
 
Top