0

我想为我的游戏创建灯光效果。我做了一些研究,我可以通过绘制一个半透明的正方形并剪下一个圆形或自定义精灵来做到这一点。我在这里查看了本教程-> https://www.yoyogames.com/blog/476/quick-and-simple-lighting

我的代码运行,但它只显示黑屏,并没有从中删除精灵。有什么我想念的吗

CREATE EVENT
////////////
surface=-1;

DRAW EVENT
//////////
colortemp=draw_get_color();
cw=camera_get_view_width(view_camera[0]);
ch=camera_get_view_height(view_camera[0]);
cx=camera_get_view_x(view_camera[0]);
cy=camera_get_view_y(view_camera[0]);
if(!surface_exists(surface)){
    surface=surface_create(cw,ch);
    surface_set_target(surface);
    draw_set_color(c_black);
    draw_set_alpha(0);
    draw_rectangle(0,0,cw,ch,false);
    surface_reset_target();
}
if(surface_exists(surface)){
    surface_set_target(surface);
    //Draws the rectangle
    draw_set_color(c_black);
    draw_set_alpha(0.8);
    draw_rectangle(0,0,cw,ch,-1);
    //Draws the sprite
    gpu_set_blendmode(bm_subtract);
    draw_set_color(c_white);
    draw_set_alpha(1); 
    draw_sprite_ext(light_source,0,(player.x+player.sprite_width/2),(player.y+player.sprite_height/2),1,1,0,c_white,1);
    //Resets variables
    gpu_set_blendmode(bm_normal);
    draw_set_color(colortemp);
    draw_set_alpha(1);
    //resets target
    surface_reset_target();
    //Draws surface
    draw_surface(surface,cx,cy);
    //frees the screen to prevent memory leaks
    if surface_exists(surface){
        surface_free(surface);
    }
}
4

0 回答 0