Animated tiles using s̶p̶a̶w̶n̶ ̶s̶p̶r̶i̶t̶e̶s̶ functions

Get help using Construct 2

Post » Wed May 25, 2016 12:23 am

Zebbi wrote:Okay, so I need to run a loop to create an animated sprite for each of the tiles of a specific ID? I'm not really sure how to go about doing this.


So, do you like that x&y loop in that capx ?
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Post » Wed May 25, 2016 12:17 pm

99Instances2Go wrote:
Zebbi wrote:Okay, so I need to run a loop to create an animated sprite for each of the tiles of a specific ID? I'm not really sure how to go about doing this.


So, do you like that x&y loop in that capx ?

yes
Zebbi wrote:Perfect, thankyou! Especially like the trick to only work on tiles in the viewport to save on resources, brilliant example!!
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Tue Feb 28, 2017 7:42 pm

Magistross wrote:You can actually animate tiles themselves, but you need to get creative. Basically, you should ensure that all animated tile sprites are consecutive in the spritesheet, and then, using a for loop, you iterate through all visible tiles and normalize tile IDs that refer to animated tile to the tile ID they should actually show.

Here's a small example.

https://dl.dropboxusercontent.com/u/700 ... lemap.capx


@Magistross
Just digging this old thread up, having a bit of trouble with this?
Image
Can't for the life of me see what's wrong with that?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Wed Mar 01, 2017 6:25 am

If everything is like in my capx, I don't see why it wouldn't work. However, without your capx it's hard to really see what's going on.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed Mar 01, 2017 7:47 am

Make animTick static.
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Post » Wed Mar 01, 2017 8:46 am

Magistross wrote:If everything is like in my capx, I don't see why it wouldn't work. However, without your capx it's hard to really see what's going on.


I'll post it when I get home from work, it was exactly the same, I just have more tiles. It looks like I changed the math to suit, but nothing moves.
99Instances2Go wrote:Make animTick static.

Static, you say?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Wed Mar 01, 2017 8:55 am

B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Post » Wed Mar 01, 2017 5:37 pm

Yep, nice catch @99Instances2Go. A local variable get reseted to its default value every tick. Making it static will make it work as if the variable was global, but retain its local scope.

Also, @Zebbi, keep in mind this system is not framerate independent, I believed you should use wallclocktime instead of tickcount to increment animTick.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed Mar 01, 2017 6:14 pm

Magistross wrote:Yep, nice catch @99Instances2Go. A local variable get reseted to its default value every tick. Making it static will make it work as if the variable was global, but retain its local scope.

Also, @Zebbi, keep in mind this system is not framerate independent, I believed you should use wallclocktime instead of tickcount to increment animTick.

EDIT: Changed to global and it works! It was just the viewport layer was set wrong, I ALWAYS make this mistake! :oops: :oops: :oops: :oops:

Out curiosity, can you switch out tickcount for wallclocktime in just one expression? I believe I already have a variable for changing wallclocktimeold to wallclocktimecurrent if there's a difference, but doing it in one line would be much handier.
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Thu Mar 02, 2017 4:01 am

You can't really switch those out. wallclocktime is incremented by dt every tick, the easiest thing would probably be using this dt directly.

Like this :
Image

In this image, animTick is incremeted 4 times per second.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Previous

Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 8 guests