how to check if there is a drawn image (dynamic sprite) at x,y in room?

Started by arj0n, Sat 20/03/2021 19:06:46

Previous topic - Next topic

arj0n

After drawing a dynamic sprite in the room:
Code: ags

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

Gilbert

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 is still relevant here.

arj0n

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.

Crimson Wizard

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

SMF spam blocked by CleanTalk