How do I achieve this effect without repeating a sprite?

Get help using Construct 2

Post » Fri Sep 02, 2016 6:43 pm

Hi. So I'm making my very first game and project and I ran into a problem.

I don't know how can I achieve this "waterfall" effect without duplicating my 16x16 animated sprite in order to achieve the water movement effect. Ideal would be to use a tiledbackground but those can't have frames to swap and create an animation.

I know by using my logic repeating a sprite like 10 times per animation, would be like a 100 sprites duplicated per layout. I'm sure I will run into problems with that.

Is there any way to achieve the same effect? I tried the Scroll plugin by Somebody but I don't thin that works here.

Here's my game and what I mean:

Image
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Fri Sep 02, 2016 6:53 pm

Use a particle system? The particle being a section of your sprite, aim it down. Take out any speed randomization and set the cone angle to 0 so it comes down in a single strip.

https://dl.dropboxusercontent.com/u/729 ... rFall.capx
Image
B
45
S
17
G
2
Posts: 201
Reputation: 4,501

Post » Fri Sep 02, 2016 7:40 pm

ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Sat Sep 03, 2016 5:59 am

I see someone have already mentioned of using the easier particles system already. but if in case that you have lots of waterfalls (implying tons of particle instances on screen, your game's framerate might drop to a crawl especially if this is on the weaker mobile devices.

If you don't need to optimize, stop reading. But if you do need to optimize, this is another method that uses far fewer instances although also more complicated:

You can have animated Tiles via event sheet using layer switching method:

What you need is to create multiple Tiles with respect to number of frames you have. (ex. waterfall_1, waterfall_2 up to waterfall_n, where n is total number of animation frames you have) Put all of these in an unused layout.

Then, in the layout, create number of layers with respect to total number of waterfall frames you have (ex. "waterfall_layer1", "waterfall_layer2" up to "waterfall_layerX")

Now, create waterfall_1 at where you want these waterfalls to be on layer "waterfall_layer1".

Now, on start of layout event, you check through all waterfall_1 Tiles using For Each loop, and do the following:
- create waterfall_2 tile on layer "waterfall_layer2"
- create waterfall_3 tile on layer "waterfall_layer3"
...
...
(do this up to the last waterfall tile and last layer)


Now, create 2 global variables called "waterfallstep" and "modwaterfallstep" and set them to 0 and create another global variable called "totalnumberofwaterfallframes" and set it to the number of total animating frames you have for your waterfall.

Now, create "every 0.1 sec." event , where u will increment waterfallstep by 1 and set modwaterfallstep using this formula:

modwaterfallstep = waterfallstep % totalnumberofwaterfallframes

Because of the % modulo operator, this formula will only yield increasing number from 0 to number of waterfall frames you have and then the increasing number will be thrown back to 0 thanks to % modulo operator.

Now, after the action above, you use for loop i = 1 to totalnumberofwaterfallframes. In this loop, you do this:

if (i = modwaterfallstep), set layer "waterfall_layer" + i to be visible.
Else set layer "waterfall_layer" + i to be invisible.

This means, in "every 0.1 sec" event, the event sheet will go through all of your waterfall layers and will make the only one unique layer that is equal to modwaterfallstep to be visible, while all other layers are turned invisible.

This will give you the impression of animating tiles. It is a lot more work and hectic, but you can waterfall as long as you like without affecting performance (unlike using particles). All of these waterfall tiles are also not iterated through in every tick (unlike particles as well). Therefore, there won't be much of any performance cost here at all.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Sat Sep 03, 2016 7:33 am

I don't understand the issue. Why not just use an animated sprite?
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Sat Sep 03, 2016 7:41 am

Cuz using animated sprites for waterfall mean the number of objects required for copy and paste could be tremedous depending on how many waterfalls there are in the layout.

Also, if the waterfall is long, how many waterfall objects do u need for one waterfall?

If a layout has just a few short waterfalls, then sure, you can just copy paste animated Sprites all over and call it a day. (I did this in my game. :P )
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Sat Sep 03, 2016 8:49 am

TwinBlazar wrote:I see someone have already mentioned of using the easier particles system already. but if in case that you have lots of waterfalls (implying tons of particle instances on screen, your game's framerate might drop to a crawl especially if this is on the weaker mobile devices.

If you don't need to optimize, stop reading. But if you do need to optimize, this is another method that uses far fewer instances although also more complicated:

You can have animated Tiles via event sheet using layer switching method:

What you need is to create multiple Tiles with respect to number of frames you have. (ex. waterfall_1, waterfall_2 up to waterfall_n, where n is total number of animation frames you have) Put all of these in an unused layout.

Then, in the layout, create number of layers with respect to total number of waterfall frames you have (ex. "waterfall_layer1", "waterfall_layer2" up to "waterfall_layerX")

Now, create waterfall_1 at where you want these waterfalls to be on layer "waterfall_layer1".

Now, on start of layout event, you check through all waterfall_1 Tiles using For Each loop, and do the following:
- create waterfall_2 tile on layer "waterfall_layer2"
- create waterfall_3 tile on layer "waterfall_layer3"
...
...
(do this up to the last waterfall tile and last layer)


Now, create 2 global variables called "waterfallstep" and "modwaterfallstep" and set them to 0 and create another global variable called "totalnumberofwaterfallframes" and set it to the number of total animating frames you have for your waterfall.

Now, create "every 0.1 sec." event , where u will increment waterfallstep by 1 and set modwaterfallstep using this formula:

modwaterfallstep = waterfallstep % totalnumberofwaterfallframes

Because of the % modulo operator, this formula will only yield increasing number from 0 to number of waterfall frames you have and then the increasing number will be thrown back to 0 thanks to % modulo operator.

Now, after the action above, you use for loop i = 1 to totalnumberofwaterfallframes. In this loop, you do this:

if (i = modwaterfallstep), set layer "waterfall_layer" + i to be visible.
Else set layer "waterfall_layer" + i to be invisible.

This means, in "every 0.1 sec" event, the event sheet will go through all of your waterfall layers and will make the only one unique layer that is equal to modwaterfallstep to be visible, while all other layers are turned invisible.

This will give you the impression of animating tiles. It is a lot more work and hectic, but you can waterfall as long as you like without affecting performance (unlike using particles). All of these waterfall tiles are also not iterated through in every tick (unlike particles as well). Therefore, there won't be much of any performance cost here at all.


Thank you I will try it out whenever I have some time
B
14
S
5
Posts: 248
Reputation: 1,705


Return to How do I....?

Who is online

Users browsing this forum: plinkie, zenox98 and 10 guests