Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lewis on Sun 10/05/2020 14:23:31

Title: Is there a way to draw a sprite behind walk-behind areas?
Post by: Lewis on Sun 10/05/2020 14:23:31
Question per the thread title, really.

I'm creating a zombie shooter engine within AGS because of course I am. Slowly but surely it's coming together.

When the player kills a zombie, I'm getting it to show a 'zombie death animation' then replace the zombie with a sprite drawn onto the background, so I'm not cluttering the screen up with characters, as there's no need to interact with zombie corpses (both in the game and in life in general). So I'm using this code:

Code (ags) Select
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(cZombie.x-16, cZombie.y-48, 105); //weird quirk in AGS offsets the sprite coordinates from the character coordinates. No idea why, but offsetting the coordinates like this works.
surface.Release();


Of course, the issue is that if the zombie dies when behind a 'walk behind' area, the sprite is drawn over the top of it, because I'm simply drawing the sprite onto the background.

Anyone got any simple / elegant solutions for this?
Title: Re: Is there a way to draw a sprite behind walk-behind areas?
Post by: Crimson Wizard on Sun 10/05/2020 14:45:09
You cannot do that as walk-behinds use room background image.

Perhaps, make a room object instead of walk-behind.


Quote from: Lewis on Sun 10/05/2020 14:23:31
surface.DrawImage(cZombie.x-16, cZombie.y-48, 105); //weird quirk in AGS offsets the sprite coordinates from the character coordinates. No idea why, but offsetting the coordinates like this works.

It's a matter of coordinate origin. DrawImage requires coordinates of a top-left corner, while character's X,Y are coordinates of it's bottom/center point.
Something like this should calculate proper drawimage coordinates:
Code (ags) Select

ViewFrame* vf = Game.GetViewFrame(cZombie.View, cZombie.Loop, cZombie.Frame);
int sprite = vf.Graphic;
int width = Game.SpriteWidth[sprite];
int height = Game.SpriteHeight[sprite];
int draw_x = cZombie.x - width / 2;
int draw_y = cZombie.y - height;

Title: Re: Is there a way to draw a sprite behind walk-behind areas?
Post by: Mandle on Sun 10/05/2020 14:47:24
I have no idea about how to code such a thing, or even if it can be done, but my quick-and-dirty fix would be to replace the walkbehinds with objects cropped from the background, with their baselines set to the bottom of the screen so everything goes behind them.

(EDIT: CW beat me to it, but I'll just keep my post here anyway as it goes into a little more, probably unneeded, detail.)
Title: Re: Is there a way to draw a sprite behind walk-behind areas?
Post by: Lewis on Sun 10/05/2020 15:44:22
Thanks both! Yeah, objects was gonna be my contingency plan. It's just very mildly fiddlier, so was hoping to avoid it, but no big deal. Thanks again!
Title: Re: Is there a way to draw a sprite behind walk-behind areas?
Post by: Cassiebsg on Sun 10/05/2020 16:31:15
I guess, in theory, one could use the walkbehind mask, and use it to cut out the dynamic sprite, and then draw the cut off sprite on to the BG... but why complicate something that is as simple as having the "walk-behind" on an object.  ;)