Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Sat 20/03/2021 19:06:46

Title: how to check if there is a drawn image (dynamic sprite) at x,y in room?
Post by: arj0n on Sat 20/03/2021 19:06:46
After drawing a dynamic sprite in the room:
Code (ags) Select

DynamicSprite* ds = DynamicSprite.CreateFromExistingSprite (1, false);
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(0, 50, ds.Graphic);


The player walks over a grid by keyboard control.
I first want to check if there is a drawn sprite (e.g. a wall) in the destination grid cell before the player is allowed to work in a direction.

How do I check code-wise if there's a drawn image at a certain x,y coordinate in the room (say at 0,50)?
Title: Re: how to check if there is a drawn image (dynamic sprite) at x,y in room?
Post by: Gilbert on Sun 21/03/2021 04:59:29
Usual practice in game design is NOT to use the graphics representation as what's present in specific location of the game field. Just track whatever you place on the grid with a data structure, e.g. an array (too bad I think AGS doesn't support 2D arrays yet so you need to simulate them).

Edit:
I think this very old thread (https://www.adventuregamestudio.co.uk/forums/?topic=6918.0) is still relevant here.
Title: Re: how to check if there is a drawn image (dynamic sprite) at x,y in room?
Post by: arj0n on Sun 21/03/2021 12:07:52
Thanx, Gilbert. I was already using an array to keep track what graphic  is placed where. I was just hoping there was an easier way to check what is drawn where.
Title: Re: how to check if there is a drawn image (dynamic sprite) at x,y in room?
Post by: Crimson Wizard on Sun 21/03/2021 17:18:24
Quote from: arj0n on Sun 21/03/2021 12:07:52
Thanx, Gilbert. I was already using an array to keep track what graphic  is placed where. I was just hoping there was an easier way to check what is drawn where.

But checking array element is the easiest possible way existing in situation like this. Even if AGS stored information about drawn sprite it still would be stored in some kind of array.
If you mean easier in terms of using in code, perhaps adding a helper function that checks your underlying arrays and returns sprite number or type of tile would simplify this somehow.

In regards to DrawImage, it copies pixels over from one bitmap to another and does not add any record of this action. Technically one would have to do pixel by pixel comparison (and of course that would break if you happen to draw another layer of sprites above that).