Drawing/Clearing Sprites on a Room Surface

Started by Terrorcell, Tue 06/12/2011 14:48:16

Previous topic - Next topic

Terrorcell

I'm a little unsure as to how to go about drawing a dynamic sprite image onto a room surface and somehow being able to remove that image from the background later, returning the background to how it was before it was first drawn onto.
I can't use overlays because it's a scrollable room, and it gets even more difficult when multiple of these dynamic sprites need to be moving around the room surface at the same time (as close to 'at the same time' as computers can manage).
I'm sorry if this seems like a bit of a poor effort but it's late and I'm tired :P.
Any ideas?

Khris

Have you considered using non-clickable objects instead?

If you have to use DynamicSprites and want to move them around, too, you basically have to duplicate how objects are handled by the engine. In other words, store the positions of each sprite and make a "backup" of the room background when the room is loaded.
As soon as one of the DynamicSprites is supposed to "move", redraw everything.

Use this to make a backup of the background:
Code: ags
DynamicSprite*backup;

// inside room_Load()
  backup = DynamicSprite.CreateFromBackground();


You can restore the room background anytime using:
Code: ags
  DrawingSurface*ds = Room.GetDrawingSurfaceForBackground();
  ds.DrawImage(0, 0, backup.Graphic);

Terrorcell

The background part is alright, its just placing the sprite down to be removed at a later time that is the pain.
Also, there may well be over a hundred of these sprites (in a worst case scenario) moving around at once, so objects aren't that much of an option in this case.

Unless dynamically creating 'Objects' with pointers still counts towards the max number of objects you can have per room...?

Khris

Creating an Object pointer doesn't increase the number of objects, just the number of pointers (just like adding signposts doesn't add towns).

What exactly is a pain? You create a struct array that holds position, visibility and sprite slot. Each time something changes, you draw the background, then iterate through the array elements and draw the visible sprites at their current position on top.

What exactly do you need help with?

Terrorcell

Ah yes, I just figured it out.

Quote from: KhrisCreating an Object pointer doesn't increase the number of objects, just the number of pointers (just like adding signposts doesn't add towns).

I meant by using the 'new' keyword and, ultimately, the 'delete' keyword. I like the analogy though :)

monkey0506

The only thing you can use AGS' new keyword for is to create dynamic arrays, and there is no delete keyword in AGS.

However, dynamic arrays are a pointer type, so int[] is comparable to int*, Object*[] is comparable to Object**, etc. (although the compiler won't allow you to use pointer syntax, only array syntax).

SMF spam blocked by CleanTalk