Dynamicsprite rotating a character [SOLVED]

Started by Ryan Timothy B, Sun 14/06/2009 23:28:37

Previous topic - Next topic

Ryan Timothy B

If I were to rotate a sprite, is it not possible to place that rotated sprite as the 'character' image?

Similar to how you can change the graphic of an object:
object[0].Graphic = sprite.Graphic;

I'm probably overlooking it in the search and the help index.

The reason I ask, is it's easier to add 20 characters to one room, than it is to add 20 objects to multiple rooms.

GuyAwesome

#1
I think you'd use the ViewFrame functions, particularly ViewFrame.Graphic, like (mostly lifted from the manual, and untested)

Code: ags

ViewFrame *frame = Game.GetViewFrame(cNpc.View, cNpc.Loop, cNpc.Frame);
frame.Graphic = sprite.Graphic;


If you wanted the characters to be mobile/animated, you'd probably have to set EVERY frame of EVERY loop, but it's doable. (Actually, for animation you could probably just directly update the dynamic sprite in RepExec.) For single sprite, room-independent 'object' replacements, though, it should be that simple.

Ryan Timothy B

#2
That appears to have given me an error message while playing.
Hmm

EDIT: Ahh, figured it out.  You must delete the sprite once it's done with.  That surely puts me in a pickle... Guess I'll have to have it delete the sprites before the game closes?  What if someone X's out the game, is it possible to have an ifgamequit function that runs when it's X'd out?

Anyway, thanks for the help Guy. :P

GarageGothic

Not an issue, it doesn't matter if the sprite doesn't get deleted before the game quits. Windows will automatically free up the memory whether you use the internal quit function, or exit the game using Alt+f4 or Alt+X. And as of the latest AGS beta, the warning will only be logged as long as the game is run in debug mode.

Ryan Timothy B

Wow, I feel like a tard.
Took me forever to figure out that:  DynamicSprite* sprite;  was actually creating a variable called sprite.

*smacks self on head*

Each time I ran the rotate function it was only holding the sprite within that function, and as soon as the function closed, the graphic wasn't shown anymore.
Oh well.. Now I know.

GuyAwesome

I was going to mention that last night - I tried the code out and that was the only problem I had (no crashes, just cNpc looking like a small blue cup - must be where the code was running from). But you said you'd solved it before I could post so I went to bed instead :) Sorry about that.

SMF spam blocked by CleanTalk