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

Legacy GM Simple shadows in topdown shooter

M

mysticjim

Guest
Hello

I've been collecting lots of possible ways to do this, some more practical than others, but i thought I'd throw this out here to get some feedback and maybe other suggestions I haven't discovered yet.

So, I'm working on a top down shooter, literally all the graphics are portrayed in a plan view. I wanted to impliment shadows to all the characters and buildings in the game. The game is set outdoors, mostly, in what I'd consider normal daylight. I've already shaded most of my static graphics like buildings imagining the light is hitting it from the bottom left, so I want to generate simple shadows going off to the top right for all of them, and for the shadows to reflect their imagined height.

This was fine with characters, a simple close drop shadow works fine as it's so close to the character object, but buildings are causing me issues.

Initially I was actually drawing the shadow and building that into the sprite image as I drew it in Photoshop - which was a massive pain and not very efficient as I have buildings and things of different sizes. I really don't want to have to draw in a shadow manually for every building!

Drop shadows are easy to generate in the draw event, but no good buildings if you want to give a sense of height as they simply make the building look like it's hovering.

I found this brilliant tutorial by Friendly Cosmonaut;


It involves using the draw_sprite_pos feature - which I initially thought was a winner, until I realised that this sprite function doesn't naturally let you set the colour of the shadow sprite to c_black. Friendly Cosmonaut gets around this by using gpu_set_fog - however I'm currently using GMS1.4 and this function isn't available (another reason for me to upgrade soon, me thinks!)

So I was back to the drawing board.

I see lots of fancy lighting systems tutorials but they all seem to deal with dynamic shadows, i.e. moving light sources and stuff. I'd have thought what I need is much simpler - just a single light source effecting all the buildings in the same way - a generic 45 degree shadow on everything.

I think I've ruled out all functions native to GMS1.4 using sprite commands - they either can't put the sprite in the right shape or in the right place, or don't have the right means to manipulate the colour of the shadow.

Is there a simple and elegant solution that I've missed? I've seen a few comments about manipulating primitives and surfaces, and a few things about shaders, both of which looked a bit scary in terms of complexity. If they're viable solutions does anyone know a kind of 'baby-steps' approach to figuring those out?
 
M

mysticjim

Guest
Okay. Have managed to make something workable using this technique, although I did hit the problem Friendly Cosmonaut talks about with overlapping shadows. Looking at her solution, that does look entirely GMS2. I got around it with a slightly labour intensive solution - I created simple drop shadow by drawing the sprite coloured in black with half opacity and then filled in the gaps using sprite draw pos to create the illusion of a cast shadow.
Capture.JPG

As you can see, obviously ignoring how bad the art is(!) - it sort of works. I can recycle the code for all my buildings, which are a pretty uniform shape, but I wonder if anyone has any alternative suggestions?

I'd also like to soften the shadows to make them look nicer. I'm wondering if a better approach is to draw and shade the shadows as primitives and then copy them to a surface and apply blur. Neither of which I've really experimented with before. Is this a viable solution?
 
Top