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

GameMaker Black Screen when using a Camera object

T

The Count

Guest
Up until now in my project, I've just been using the built-in room Camera and Viewport 0, following my Player object. As I start adding more advanced things like a HUD and dialog boxes, I'd like to have more control over my camera, so I set out to watch a tutorial from Shaun Spalding on how to make and manipulate a camera in GML.

I followed the instructions to a 'T', but when I drop my camera object into my room and run the game, no matter where it is, what layer it's in, and no matter what its depth is, I always get a black screen when I run the game. You can hear the music and the action, you can control the player, but you just can't see anything at all. As soon as I remove the camera object from my room and run the game again, the game runs like normal.

I've checked Preferences, I've tried a gamut of different depths and layers, done countless Google searches, and even reached out in the Discord chat, but I have not been able to find a solution. I feel like it's going to be something slap-on-head stupid, but as of right now I can't figure it out.

Thanks!
 

TheouAegis

Member
Does your camera disable automatic drawing or the application surface? I don't know Shaun's camera tutorial...
 
T

The Count

Guest
Does your camera disable automatic drawing or the application surface? I don't know Shaun's camera tutorial...
Not in the code, it doesn't. All it does is sets the camera variable, sets a view matrix and a projection matrix, assigns the matrices to the camera, and sets view_camera[0] to the camera variable.
 
Maybe you could post your camera code?

Have you set the following:
Code:
view_visible[0] = true;
view_enabled = true;
 
T

The Count

Guest
Maybe you could post your camera code?

Have you set the following:
Code:
view_visible[0] = true;
view_enabled = true;
Unfortunately, adding either of those had no effect. Here's my camera code:

camera = camera_create();

var viewmat = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var projmat = matrix_build_projection_ortho(256,96,1,50);

camera_set_view_mat(camera,viewmat);
camera_set_proj_mat(camera,projmat);

view_camera[0] = camera;

follow = obj_player;
xTo = x;
yTo = y;


You can ignore the follow = obj_player stuff, it doesn't work whether that's there or not.
 
That code you posted for the camera works for me.

Here's my test room settings:
upload_2018-5-4_12-14-23.png
Everything else is not ticked.

Camera Create Event:
Code:
x = room_width / 2;
y = room_height / 2;

camera = camera_create();
var viewmat = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var projmat = matrix_build_projection_ortho(256,96,1,50);

camera_set_view_mat(camera,viewmat);
camera_set_proj_mat(camera,projmat);

view_camera[0] = camera;
I notice when you are building your projection matrix, you've set the zfar parameter to 50.

What are the depths of your layers in your room? I remember by default the auto-gap between layers is 100, so it's possible the layers you want to draw are outside the range set by the projection matrix (from layer/ depth 1 -> 50 in your example)

You may have already tried this, but if you haven't, try changing the zfar value to 32000, or some large number that is greater than your highest number layer depth.
 
T

The Count

Guest
That code you posted for the camera works for me.

Here's my test room settings:
View attachment 18195
Everything else is not ticked.

Camera Create Event:
Code:
x = room_width / 2;
y = room_height / 2;

camera = camera_create();
var viewmat = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var projmat = matrix_build_projection_ortho(256,96,1,50);

camera_set_view_mat(camera,viewmat);
camera_set_proj_mat(camera,projmat);

view_camera[0] = camera;
I notice when you are building your projection matrix, you've set the zfar parameter to 50.

What are the depths of your layers in your room? I remember by default the auto-gap between layers is 100, so it's possible the layers you want to draw are outside the range set by the projection matrix (from layer/ depth 1 -> 50 in your example)

You may have already tried this, but if you haven't, try changing the zfar value to 32000, or some large number that is greater than your highest number layer depth.
No dice, unfortunately. Just tried your advice for zfar and for znear to be sure, and tried both positive 32000 and negative 32000. Same result.

Thinking about it, I started going through a shader tutorial at one point and stopped. Thought that could be the culprit, but I deleted my shader objects to be sure and it made no difference (I never placed them in the room to begin with). I'm not sure how surfaces and stuff like that work, but I don't have anything in my code mentioning surfaces, anyway. This is so weird.
 
Ok, so this only happens when you drop the camera into the room.

Have you posted all the code from your camera object? If not, please do so.

Alternatively, if you are able and don't mind doing so, you could export your project to a YYZ file and share it somewhere like dropbox and I'll take a look directly what's going on.
 
T

The Count

Guest
The only thing I left out of the camera code that I posted here was the Step event stuff (which includes the xTo and yTo code), but that isn't the reason why the camera doesn't work. It already wasn't working before I got to the Step event, I just figured I'd finish his tutorial and work on the black screen stuff afterwards. I will export to a YYZ file and link you momentarily. Thanks for your help.
 
T

The Count

Guest
Direct messaged you.

Edit: The camera obj is not in the room currently, you'll have to drop it in.
 
Hi, so I know I'm super super late to this thread, but I'm having the exact same problem with my game as The Count was. Did you happen to resolve the issue externally, and if you did can I please get help with this too?
 
Hi there,

There was a line in The Count's code as follows that was interfering with camera code, here's the exact message I sent them.

Ok, I don't know exactly why this is happening, but, in your obj_hud_hp Step Event, you have the following line:

camera_set_view_target(view_camera[0], obj_player);

As soon as I comment out that line, the camera draws everything correctly.

I can only guess it is overwriting the manual camera settings that your obj_camera has.
They also had to increase the zfar value as there were layers with higher depth so they weren't being drawn.

Finally, another object that wasn't drawing was manually setting the wrong depth in its Create Event, which was causing it to not be drawn.

Don't know if the above will apply to your particular case, best of luck.
 
Top