Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: strazer on Wed 28/04/2004 11:01:54

Title: How to return the sprite slot of a frame? (IMPLEMENTED)
Post by: strazer on Wed 28/04/2004 11:01:54
Is it possible to return the sprite slot of a frame in a view?

I've emulated the functionality of the rain plugin, but in order to draw the raindrops in front of the player character I have to hide him (with SetCharacterTransparency(EGO, 100) to retain interactions) and rawdraw his frames onto the background before drawing the rain over him:

// curslot = a whole lot of else-ifs here :(
RawDrawImage(player.x-(GetGameParameter(GP_SPRITEWIDTH, curslot, 0, 0)/2), player.y-GetGameParameter(GP_SPRITEHEIGHT, curslot, 0, 0), curslot);
// draw rain here

It would be a lot easier if I could just do

curslot = GetSpriteSlot(player.view, player.loop, player.frame);

Maybe if GetSpriteSlot returned a negative value for flipped frames, RawDrawImage could draw them flipped as well?
(Edit: AGS v2.71 RC 1: Added GP_ISFRAMEFLIPPED option to GetGameParameter.)

If not a seperate function, how about an addition the GetGameParameter function (GP_SPRITESLOT - Returns sprite slot number of frame DATA3 in loop DATA2 of view DATA1)?
(Edit: AGS v2.61 RC 1: Added GP_FRAMEIMAGE option to GetGameParameter.)
Title: Re:GetSpriteSlot?
Post by: Gilbert on Wed 28/04/2004 11:20:51
I think it's not possible at the moment (unless I missed something), a workaround is that you plan carefully on the sprite numbers of the characters before assigning them to a view (it's a bit complicated, but you can right-click a sprite and change its slot).

For example:
"Down" view of the character uses slots:
1001,1002,...,1010
"Left" view of character uses slots:
1101,1102,...,1110

blah bla bla

Then you can check the frame and loop of the character to calculate the sprite number:

slot=1000+(player.loop*100)+player.frame;

It may be a bit complicated, but as you're doing some complicated things already, I think it's acceptable.


On the other hand, however, I think it's still worth having the function you mentioned implemented, as it can be handy. (CJ: read ;) )


Title: Re:GetSpriteSlot?
Post by: strazer on Wed 28/04/2004 11:37:51
Quoteyou can right-click a sprite and change its slot

Cool, I didn't know that.
That will have to do for now, thank you!
Title: Re:GetSpriteSlot?
Post by: Gilbert on Wed 28/04/2004 11:46:41
Well, it's not explicitly documented to prevent users from messing up their games (like a game crashes because they changed teh sprite slot of a sprite originally assigned to a view, this is similar to deleting a sprite without ever thinking, ironically, this feature is added mainly to compensate for the fatal crashes caused by deleting sprites).

So, shhhh, don't spread out the words and recommend other to use this feature (unless they really know what they're doing). ;)
Title: Re:GetSpriteSlot?
Post by: Pumaman on Thu 29/04/2004 21:05:18
A new option to GetGameParameter sounds like the best plan here, I'll add it to my list.