Lerp sprite size

Get help using Construct 2

Post » Fri Jul 05, 2013 11:47 pm

I've been trying to work out how to half the size of a sprite and then return it back to its' original size using lerp.

I've managed to get the sprite to increase and decrease in size using lerp. However, it doesn't seem to be increasing/decreasing by the right amount. It's probably some bad maths on my part, or just a wrong use of lerp ^^. Any help would be muchly appreciated.

Pseudo code:

On event:
- Trigger once whilst true --> set size to:
          Width: lerp(Self.width,Self.Width/2,dt*self.scrollspeed)
          Height:lerp(self.Height,self.Height/2,dt*self.scrollspeed)

Else:
- Trigger once whilst true --> set size to:
          Width: lerp(Self.width,Self.Width*2,dt*self.scrollspeed)
          Height:lerp(self.Height,self.Height*2,dt*self.scrollspeed)


Thanks for reading :)

Toby122013-07-05 23:48:31
B
11
S
3
Posts: 43
Reputation: 1,561

Post » Fri Jul 05, 2013 11:59 pm

It's hard to tell without looking at a .capx - but have you tried something like floor(lerp(Self.width,Self.Width*2,dt*self.scrollspeed)) - not 100% sure of the syntax - but using floor will force integers rather than fractions, which is what could be messing up your sizes perhaps.
B
63
S
24
G
4
Posts: 202
Reputation: 6,864

Post » Sat Jul 06, 2013 12:22 am

This isn't the full capx as I've got a fair bit of work in it, but it's got the same events etc... for controlling the size of a sprite.

https://dl.dropboxusercontent.com/u/17611007/Example.capx

I tried your suggestion, but unfortunately it didn't work. Thanks for the help though! :D
B
11
S
3
Posts: 43
Reputation: 1,561

Post » Sat Jul 06, 2013 11:41 am

@Toby12
lerp is mostly used to animate over time, and as you use a trigger once, it don't work right here.

2 solutions :
- either you want the sprite to go full size/half size right away, and then lerp is of no use here. Just multiply the size by 2 or half it depending on what you need
- either you want the sprite to go smoothly from one size to the other. A little harder to describe, you can find it in my capx :)Guizmus2013-07-06 11:41:39
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Sat Jul 06, 2013 12:56 pm

Thanks a bunch for the help, Guizmus! Worked a charm :). I used trigger once to stop the size constantly increasing, but using the two variables you added has solved that :D.

If I finish this project I'll be sure to give you a shout out for your help :)
B
11
S
3
Posts: 43
Reputation: 1,561

Post » Sat Jul 06, 2013 1:41 pm

@Toby12
No problem :)
I didn't optimize it though, as it was just a sample. If you add this on a lot of objects, be sure to use the scale instead (scale = height/width) with th same trick, initialScale being then a variable on your button. Less variables = better :D
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Sat Jul 06, 2013 3:59 pm

Will do, thanks for the tip :D!
B
11
S
3
Posts: 43
Reputation: 1,561

Post » Sun Aug 25, 2013 12:52 am

@Guizmus - awesome capx, very useful, thanks a lot.

@Toby12 - thanks for posting my exact question and getting it answered. I was just having this problem.Manley232013-08-25 00:53:25
B
33
S
7
G
8
Posts: 312
Reputation: 8,528


Return to How do I....?

Who is online

Users browsing this forum: MuchaDev, tetuan, tikuna and 11 guests