• 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.

Question - Code Assigning Cameras to Multiple Views

TheMagician

Member
I want to create a camera which I then assign to a viewport in the current room as well as a viewport in another room (basically I want to set up the viewports in all rooms at the beginning of the game). I don't use any of the view checkboxes in the Room Editor.

Here's the code in the Create Event of the camera object in the first room:
Code:
//create camera
//====================
cam = camera_create_view(0,0,800,480,0,-1,-1,-1,0,0);


//setup view in current room
//====================
view_enabled = true;
view_visible[0] = true;

view_set_wport(0,800);
view_set_hport(0,480);

view_set_camera(0,cam);


//setup view in other room
//====================
room_set_view_enabled(rm_other,true);
room_set_viewport(rm_other,0,true,0,0,800,480);

room_set_camera(rm_other,0,cam);
Whenever I switch to the other room the game crashes. What am I doing wrong?

Additional Information: If I leave out this line:
Code:
view_set_camera(0,cam);
then I get a scrambled view in the current room (which is expected because I don't assign a camera to its viewport) but switching to the other room now produces the correct result (no crash and correct camera assignment).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I suspect that the fact the camera is not in a global variable could be an issue. Cameras are dynamic resources and so by assigning it to an instance variable it will be dereferenced when the current room ends or the instance is destroyed. If you look at the example in the manual for room_set_camera it uses a global varaiblñe so try using that instead.
 

TheMagician

Member
Right now the camera object is set to "persistent". I thought that should be enough to carry the information on to the next room.

However, I've now modified the code to store the variable "cam" as a global variable. The behavior doesn't change. As soon as I switch to the other room the game crashes (without any error message).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Have you run the game in debug mode and stepped through the code? If you can confirm that it is the camera causing this (or whatever else it may be), then file a bug and include a download link to the project please. :)
 
Top