Independantly drawing a sprite

Started by Galen, Mon 13/07/2009 20:01:47

Previous topic - Next topic

Galen

Hey, so I was wondering, how do I draw a sprite independantly of anything else?
I've tried fiddling around with dynamic sprites and drawing surfaces to no avail and I really would like to know the correct procedure for doing such a thing... Should I be using the dynamic sprite features or would I just be better off using a GUI or what?

GuyAwesome

What are you trying to do, and what exactly have you done with DynamicSprites and DrawingSurfaces? If you just want to draw an existing image onto the room background, DrawingSurfaces are the way to go. Something like
Code: ags

  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawImage(50, 100, 12);

Which will draw sprite 12 onto the Room background at 50, 100 (Room coords, not screen coords).

If you want to edit the sprite for use as an Object or Character graphic, then you're looking at needed DynamicSprites. Create a DynamicSprite from the existing sprite, get its DrawingSurface, draw whatever you want, set the Character/Object to use it, like this:
Code: ags

  DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(object[0].Graphic);
  DrawingSurface *surface = sprite.GetDrawingSurface();
  surface.DrawingColor = 13;
  surface.DrawLine(0, 0, 20, 20); // Draw pink diagonal line across sprite 12 ...
  surface.Release();
  object[0].Graphic = sprite.Graphic; //  ... and use it for object[0]
  // Stolen from manual...


But, really, it depends what you want to do...

Khris

Just remember to declare the DynamicSprite pointer outside any function, otherwise it is destroyed as soon as the function is finished executing and will turn into a little blue cup :)

Galen

I'm not looking at editing anything. I just want to draw a sprite somewhere on the screen and be able to move it around and delete it when necessary.

Khris

You could use an overlay, too. It depends on what you want to be displayed beneath & above the sprite.
E.g. an overlay will be obscured by GUIs.
Drawing it to the background is another possibility, but then it'll be behind characters and objects.

GuyAwesome

Like I said: Depends what you want to do :).

For what you want, a dummy Character might be the way to go. You Won't need to declare it in every room (if it's only one room, you could use a dummy Object), you don't need to worry about DynamicSprites or DrawingSurfaces - it'd just be normal positional changing (Character/Object.Move) - it could be above or below other things as needed, and you could turn it off when you wanted.
If it only has to be below other graphics you could still use DrawingSurface.DrawImage, but you'd need to remove and re-draw the image every frame - well, if the sprite needs to change position (e.g. a 'blacklight'/UV effect that follows the player character/mouse, or in a scrolling room). And if it only needs to be above (e.g. a frame or shadow effect) you could use a GUI, or Overlay as KhrisMUC suggested.

Galen

Thanks for the advice guys!
I think a GUI is probably the way forward then since there isn't much code involved in working with them.

SMF spam blocked by CleanTalk