Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: antipus on Tue 25/09/2012 03:51:54

Title: SOLVED: Saving an entire loop's worth of rotated sprites using dynamic sprites
Post by: antipus on Tue 25/09/2012 03:51:54
I realize that this is a lot like WHAM's post (http://www.adventuregamestudio.co.uk/forums/index.php?topic=46743.0) about Dynamic sprites, because that's how I got to the point that I'm at now, where I'm stuck.

Here's my problem. I'm trying to take an entire series of animated sprites (in this case, a fireball), and rotate them so the player can cast the fireball in any direction, instead of just the 8 standard ones. It's not too hard to get this to work with one sprite, but I can't use iterative code to do all seven animation frames.

The following code works (I've got rotatedMissile defined globally)...
Code (AGS) Select

ViewFrame *oldFrame = Game.GetViewFrame(VBOLTFLY, 8, 0);
rotatedMissile = DynamicSprite.CreateFromExistingSprite(5513, true);
rotatedMissile.Rotate(30);
oldFrame.Graphic = rotatedMissile.Graphic;


But when I try to do stuff like this, it rotates the final sprite and fills the rest with cups...
Code (AGS) Select

int rotateFrame = 0;
while(rotateFrame < 7){
  rotatedMissile = DynamicSprite.CreateFromExistingSprite(5513 + rotateFrame, true);
  rotatedMissile.Rotate(30);
  ViewFrame *oldFrame = Game.GetViewFrame(VBOLTFLY, 8, rotateFrame);
  oldFrame.Graphic = rotatedMissile.Graphic;
  rotateFrame++;
}


Having not used Dynamic Sprites much, I get the feeling that the problem is that I've got one sprite, and I can't possibly use that same sprite for seven different frames. However, I can't bear the thought of creating 7 different global dynamic sprites and assigning them manually. Especially because there are a lot of other things that are supposed to fly through the air at a rotated angle while animating (enemy spells), possibly at the same time. And then I'd need a whole bunch more, all of which would have to be manually assigned.

Is there any way around this? Can I get an array of Dynamic sprites, for instance? I tried "DynamicSprite *rotatedMissile[7]" and it crashed. =) Or can I get the Dynamic Sprites to save to the frame more permanently, so I can reuse the Dynamic Sprite without it clearing the graphic in the loop?
Title: Re: Saving an entire loop's worth of rotated sprites using dynamic sprites
Post by: Khris on Tue 25/09/2012 04:14:31
Creating an array of DynamicSprites is the way to go.

This should work:
Code (ags) Select
DynamicSprite*rotatedMissile[7];
int rotateFrame = 0;
while(rotateFrame < 7){
  rotatedMissile[rotateFrame] = DynamicSprite.CreateFromExistingSprite(5513 + rotateFrame, true);
  rotatedMissile[rotateFrame].Rotate((rotateFrame+1)*45);
  ViewFrame *oldFrame = Game.GetViewFrame(VBOLTFLY, 8, rotateFrame);
  oldFrame.Graphic = rotatedMissile[rotateFrame].Graphic;
  rotateFrame++;
}


Where did you declare the array? You have to do it outside any function for it to work.
Title: Re: Saving an entire loop's worth of rotated sprites using dynamic sprites
Post by: antipus on Tue 25/09/2012 12:12:28
Gracious sakes. Sorry for taking your time. Yes, that worked perfectly. Thanks, Khris!

My stupid mistake was changing DynamicSprite *rotatedMissile to DynamicSprite *rotatedMissile[7] WITHOUT changing other parts of the code. The game kept shooting back an error that I couldn't "assign value to entire array" and I thought the problem was that I couldn't MAKE an array of those. Nay, not so. It's just that I couldn't say rotatedMissile = DynamicSprite.CreateFromExistingSprite(5513, true) once I had turned it into an array.

For anyone out there reading this, this would is a sweet way to rotate larger things, like walkcycles. Now I'm waiting for someone to make "Inception: The Game."
Title: Re: SOLVED: Saving an entire loop's worth of rotated sprites using dynamic sprites
Post by: StillInThe90s on Thu 04/10/2012 00:37:41
QuoteFor anyone out there reading this, this would is a sweet way to rotate larger things, like walkcycles.
Would this really work with walkcycles? I have started doodling on a top down 360 shooter-sort-of game, but it felt like an impossible task with AGS. And I've always thought using dynamic sprites was really slow.
Could AGS really handle this? And would it perform in hi-res?