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

Game Mechanics Drawing Layer to Surface Smaller than Room Size

F

FlashyAlpaca

Guest
Ok, so here's the rundown: I'm trying to draw only the currently visible part of a tile layer to a surface. This is because I'm implementing a system in the game where a Wall tile section will fade out when the player is over top of it, giving a simulated depth to the layer. I've managed to do this by creating an object that I resize in the editor to the area I want to fade out of the Tile Layer. This object then targets the surface I drew the Tile Layer to, sets the blendmode to Subtract, and then draws a black rectangle using it's bounding box as guidlines.

The problem is that after much effort and frustration, I was only able to get this working by setting the Tile Layer's surface to the size of the room. It works, but since my rooms are usually between 4000 - 5000 pixels in width and height, this method is pretty heavy on resources.

This part here works as I want it to, just uses too many resources
How it should look (First links to a gif of example):
https://imgur.com/a/afYNgge


TileWorking.jpg

*layer_begin*
Code:
if ((event_type == ev_draw) and (event_number == 0)) {

          if(!surface_exists(obj_LayerTransparency.wall_surface)){
            obj_LayerTransparency.wall_surface = surface_create(room_width, room_height);
            surface_set_target(obj_LayerTransparency.wall_surface);
             
          }else if(surface_exists(obj_LayerTransparency.wall_surface)){ 
              surface_set_target(obj_LayerTransparency.wall_surface);
          }
     
}
The layer_end here just resets the surface target.

As you can see, it lags the game just from this plus my recording software.
What I'm looking for is a way to set the surface size to the size of the current camera view(I know how to do this) and then only draw the section of the Tile Layer that is visible to that same camera view(I can't figure this part out). I know that surfaces by default are created at (0, 0), and I've tried to accomidate for this with a number of things, none of which worked, especially seeing as how camera_apply doesn't seem to work anymore for this. GMWolf posted a fix to this here (https://forum.yoyogames.com/index.php?threads/solved-surface-moves-with-camera.53382/#post-325638) but it doesn't seem to work for me. The layer doesn't end up getting drawn at all, and I'm not sure why. This is the code I tried in the layer_begin and layer_end scripts:

*layer_begin*
Code:
if ((event_type == ev_draw) and (event_number == 0)) {

          if(!surface_exists(obj_LayerTransparency.wall_surface)){
            obj_LayerTransparency.wall_surface = surface_create(camera_get_view_width(Camera.cam), camera_get_view_height(Camera.cam));
            surface_set_target(obj_LayerTransparency.wall_surface);
             
          }else if(surface_exists(obj_LayerTransparency.wall_surface)){
               surface_set_target(obj_LayerTransparency.wall_surface);
          }
}
*layer_end*
Code:
if(event_type == ev_draw) and (event_number == 0){
        surface_reset_target();
        var or_cam = Camera.cam;
        camera_apply(camera_create_view(0,0, view_wport[view_current], view_hport[view_current]));
    
        draw_surface(obj_LayerTransparency.wall_surface, 0, 0);
        camera_apply(or_cam);
}
Screenshot of Tile Layer not being drawn
TileNotWorking.jpg
I couldn't find another thread that covers this, but if you know of one please bump me in the right direction. Thanks in advance!
 
Last edited by a moderator:
Top