Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Offsetting frame start for animating sprites

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 20:58
Hi All,

I'm cloning sprites to use as tiles in a platform game. Some of the tiles (eg spinning coins) animate in a loop. Ideally I want to be able to offset the animation of each so that they don't all look identical (ie spinning at exactly the same time). I could change the animation speed of each tile but I'd rather randomly alter their starting frame or set an offset so that whilst they all spin at the same speed, they don't all appear identical.

I'd rather AppGameKit dealt with the sprite animation rather than managing it myself so....anyone have any ideas as to how I could offset each of the animations?
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 17th Oct 2014 21:12
The star background in Sudoku In Space does exactly this, plus I rotate the tiles so that they don't look like repeated tiles.
I just do PlaySprite() and then
SetSpriteFrame(spr , random(1,GetSpriteFrameCount(spr)))

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 21:25
Cheers - just trying it now... I've got to keep them in their range I guess (the image has lots of animated sprite frames on it)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 21:33
Can cloned sprites have different animation frames? I've had some variation but only one or two - with 50 spinning coins, it would be too much of a coincidence that they all landed on the same random sprite offset.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 17th Oct 2014 21:42
Ours sure do using 10824
Odd that you don't have a lot of variation. It's harder to tell with ours because they are little star dots, but I can tell the frames are definitely not the same.
Does seem like an odd coincidence.

I use cloned sprites a lot and they can have different frames.
In fact, I have a spinner animation that highlights what you've selected on the board and in the HUD. I had to force them to match frames because it looked really bad to have them not matched.

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 21:45
Hmmmm....OK, good to know that they can have different frames on cloned sprites. I'll keep looking. I can see the logic of why it should work...but it's not!
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 21:55 Edited at: 17th Oct 2014 21:58
So...


OK, so it seems to be the GetSpriteFrameCount(SpriteID) that isn't working...because if I hardcode in some values it works
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 17th Oct 2014 21:56
Here's a project illustrating that it works.
Maybe something in your logic is off.
If you can post code maybe I can look and see something.

Attachments

Login to view attachments
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 22:13
I think I've got it! All the tiles come from a large image (well one of several 1024x1024 images) so every tile effectively has the same number of frames (64px tiles = 256 tiles per image). So I was randomly picking a frame from 1 to 256...Now, the tile only used about 25 frames. If the randomly assigned frame was outside of the play range, I'm guessing AppGameKit just starts again. So...for a few of the tiles that randomly picked the first few frames it worked, but for the majority, it chose a frame outside of the play range and so it was set to the first frame. Hence most being the same with a few different ones. If that makes sense!

So all I had to do is to force it to randomly pick tiles say 1 to 20 and they all went random.

Thanks Naphier for your help. I'm dead chuffed that it's working. Now I have to integrate it into the map loading in a more flexible way but I know it works so thanks.
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 17th Oct 2014 22:30
So, you can get the frame count of a sprite set by the command SetSpriteAnimation but it appear you can't do the same for the command PlaySprite which is a shame...

Login to post a reply

Server time is: 2024-04-23 12:13:12
Your offset time is: 2024-04-23 12:13:12