Scaling a sprite over time

0 favourites
  • 11 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • I need to create a sprite and scale it over time. Ideally it would be created at 1% and scale to 100% in about ten seconds or so. Any ideas where to start?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, i needed to do the same and got some useful advice, i cant post the url to my question so search the forums for "Change size over time".

    GL!

  • every 10 seconds Self.Width*0.01 Self.Height*0.01

  • Thanks mrPeanut. Should my action be "Set size to"? So the event looks like:

    System > Every 10 seconds > Sprite > Set size to (Self.Width*0.01, Self.Height*0.01)

  • It shouldn't be run every 10 seconds, it should run every tick.

    Every Tick

    If Sprite.Scale <1.0 -----> Sprite > Set scale to Self.Scale+0.1*dt

    This will increase it by 0.1 or 10% over the course of a second and repeat continuously until it reaches 100% or 1.0 scale. You can also add on there for it to happen if a variable is true (otherwise, this will start running once the object is created or the layout begins if it is already on the layout when you run it.)

  • Hi,

    I don't mean to step on toes but unfortunately Sprite doesn't have a scale expression. So here are the steps to get the effect you want.

    1. Add an instance variable to your sprite, call it "myscale" and give it an initial value of 0.1.

    2. Add an event with the "compare instance variable" condition and set it up as follows:

    Sprite: myscale<1.0
    ---> Sprite: add 1.0*dt to myscale
    ---> Sprite: set scale to myscale

    Note, the first action is the "add to" action under "instance variables" and the 2nd action is "set scale" under "size & position".

    This will need some tweaking to make it happen in one second. As it is now the expression 1.0*dt can be read as 1 per second, but we're going from 0.1 to 1.0 in a second, or just 0.9 in a second. So it should be like this:

    Sprite: myscale<1.0
    ---> Sprite: add 0.9*dt to myscale
    ---> Sprite: set scale to myscale

    Another thing you can deal with if you like is what I like to call over shooting. With this event the end scale will likely be a bit more than 1.0. You can use the min() expression to limit the highest value to 1.0 and set up your event like this:

    Sprite: myscale<1.0
    ---> Sprite: set myscale to min(self.myscale + 0.9*dt, 1.0)
    ---> Sprite: set scale to myscale

    As a final note you can make the duration longer or shorter by tweaking the dt expression.

    half second:

    2*0.9*dt

    two second:

    0.5*0.9*dt

  • R0J0hound

    In the Manual under Sprite Actions is the action to Set Scale. Is this not what the OP is looking for?

  • zenox98

    Yes, and I recommend it's use in my post, but a instance variable is still needed to save what the scale is set to as there is no expression for Sprite.scale builtin.

  • Thanks, everyone. I ended up using what sinneruy posted in hisother thread:

    system compare two values - normal height > sprite.height

    -- Sprite set height to sprite.height+1

    system compare two values - normal width > sprite.width

    -- Sprite set width to sprite.width+1

    Ofcourse you should define the values for normal width and normal height

    Except I changed the expression from sprite.height+1 to self.height*1.005, so the rings' speed increased as it got closer to the edge of the screen. This way the rings stayed adjacent to each other instead of forming gaps between them.

    I'm not sure yet how to post a .capx that includes the art. When I figure that out I'll post it so that makes more sense.

  • Wow, I did an awful job of explaining this beforehand. I'm periodically creating randomly colored rings that scale up until they are off of the screen (or, technically, until they reach full resolution). It currently looks something like this, with each ring scaling up over time, appearing to move outward:

    Viewable on the web: bit.ly/1anBGNs

    Anyway, it's working satisfactorily right now.

  • Another thing you can deal with if you like is what I like to call over shooting. With this event the end scale will likely be a bit more than 1.0. You can use the min() expression to limit the highest value to 1.0 and set up your event like this:

    Sprite: myscale<1.0
    ---> Sprite: set myscale to min(self.myscale + 0.9*dt, 1.0)
    ---> Sprite: set scale to myscale

    to clarify incase people got stuck like me...

    use "Set value" instead of "Add to" while using the min()

    or you could just easily use the min() expression on the Set Scale, but probably cleaner to have the instance variable have 1.0 when the sprite is at it's 1:1

    thanks R0J0hound

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