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

(Solved) Collision Checking on Asset Layer

J

JayR

Guest
I have a lighting system that creates a sprite on an Asset Layer.
The codes below are for items that emit light.
Create event:
Code:
// === Emits Light Handling =========================
// ==================================================
// Layer id which light sprite draws on.
bp_light_emit = 0;
// Brightness intensity of the light.
bp_light_emit_intensity = 0;
// ==================================================
Step event:
Code:
// For blueprints that emits light when on the ground.
if (blueprint_is_light_source(object_index) == 2) {
    if (bp_light_emit == 0) {
        bp_light_emit = layer_sprite_create(ctrl_lighting.light_layer, x, y, spr_light);
    }
    layer_sprite_xscale(bp_light_emit, blueprint_is_light_source(object_index, 0));
    layer_sprite_yscale(bp_light_emit, blueprint_is_light_source(object_index, 0));
    bp_light_emit_intensity = pulse(bp_light_emit_intensity, 0.6, 0.8, 0.25);
    layer_sprite_alpha(bp_light_emit, bp_light_emit_intensity);
}
The code below is for the object ctrl_lighting.
Create event:
Code:
// Initialize the light system.
// YouTube Tut: Simple lighting system for GMS2 - GMWolf
// https://www.youtube.com/watch?v=Un9DC0cTiP4

light_layer = layer_get_id("Lights");

var cam = view_camera[view_current];
light_surface = surface_create(camera_get_view_width(cam), camera_get_view_height(cam));

layer_script_begin(light_layer, lights_begin);
layer_script_end(light_layer, lights_end);
Now, I'm trying to get a mob to check if it's in the light or out of the light. How do I check for this collision? Any help is greatly appreciated. Thanks.
 
Z

Zachary_tzy

Guest
I'm not sure if i'm right about this but I think it's not possible to collide with a sprite with no instance id attached to it? GMWolfs tutorial uses lights as an object, whereas I think you are just drawing a sprite to the an asset layer. You could convert your lights to objects and create them on top of your light emitting objects and then check for collision. Or if you really just want to draw your lights in an asset layer, you can maybe draw to a blank surface and store that surface in a buffer, and as your player moves you read from the buffer the RGBA values to see if your player/mob is in the light or not. But not sure if it will work that well with your pulsating lights, as I notice you manipulate your sprite assets in the step event.
 
Last edited by a moderator:
J

JayR

Guest
@Zachary_tzy, thanks. I went ahead with creating the light source as an object and doing the normal collision checking from there.
 
Top