Is there a way to draw a sprite behind walk-behind areas?

Started by Lewis, Sun 10/05/2020 14:23:31

Previous topic - Next topic

Lewis

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
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?
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

Crimson Wizard

#1
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

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;


Mandle

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.)

Lewis

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!
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

Cassiebsg

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.  ;)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk