• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion surface_set_target causes my camera to break

M

Misu

Guest
I'm working on a platformer in GMS 2 and everything seems to be coming along great until I needed to do an effect for drawing textures on random shapes. I needed to use a separate new object that draws its own surface but I encountered a problem that is so strange, I believe this is more an IDE problem. Just by triggering the surface_set_target, the while camera breaks and does not follow the main character. Take a look at this image:



This is not a problem I get from GMS 1.4. I dunno why this program messed up everything with a single (unrelated) command. Hopefully, I'm missing out something about the program or this is a huge bug that needs to be resolved. Anyway, I already reported the bug and hopefully, someone here might explain to me what went wrong.
 
A

Andy

Guest
When you change the surface target (set or reset) GM resets the camera's view and projection matrices.
Save the current view and projection matrices before changing the surface target. Then reset them after a change, like:
Code:
// Save camera matrices
var _cam = view_camera[view_current];
var _proj_mat = camera_get_proj_mat(_cam); // Projection
var _view_mat = camera_get_view_mat(_cam); // View

// Set surface target
surface_set_target(_id);

// Reset camera matrices
camera_set_proj_mat(_cam, _proj_mat);
camera_set_view_mat(_cam, _view_mat);
camera_apply(_cam); // Make sure you force apply all changes to the camera, or they wont change until the next draw event.
You may not need to reset them until after resetting the surface target, it all depends on what you need. :)
 
Last edited by a moderator:
M

Misu

Guest
@Andy It didn't help. It did cause my surface drawing to show up but very tiny inside the black square. The tilesets remain unmoveable to the camera view. :/

EDIT:
Ok! Your trick DOES fix it! I had to do was reapply the camera setting AFTER resetting the surface target rather than within the surface target.

Now its working perfectly! Thanks a lot Andy! You're the best! : D
* *gives fluffy doughnut to Andy and dances happily!* *
 
Last edited:
A

Andy

Guest
Yay! :D
I’m happy this ended up working because I was completely out of other ideas. :p
*Eats the doughnut.*
 
Top