Lerp sprite size

0 favourites
  • 8 posts
From the Asset Store
220 Food Sprites in 16x16 pixel size. Perfect for items for a retro style game.
  • 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 :)

  • 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.

  • 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.

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

    I tried your suggestion, but unfortunately it didn't work. Thanks for the help though! :D

  • 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 :)
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 :)

  • 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

  • Will do, thanks for the tip :D!

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)