Scaling a sprite over time

Get help using Construct 2

Post » Mon Nov 11, 2013 2:35 pm

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?
B
4
Posts: 25
Reputation: 302

Post » Mon Nov 11, 2013 2:53 pm

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!
B
15
S
1
G
1
Posts: 15
Reputation: 1,051

Post » Mon Nov 11, 2013 4:37 pm

every 10 seconds Self.Width*0.01 Self.Height*0.01
B
9
S
3
G
3
Posts: 70
Reputation: 1,990

Post » Mon Nov 11, 2013 10:43 pm

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)
B
4
Posts: 25
Reputation: 302

Post » Mon Nov 11, 2013 11:57 pm

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.)
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Tue Nov 12, 2013 2:18 am

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:

[code]Sprite: myscale<1.0
---> Sprite: add 1.0*dt to myscale
---> Sprite: set scale to myscale[/code]
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:
[code]Sprite: myscale<1.0
---> Sprite: add 0.9*dt to myscale
---> Sprite: set scale to myscale[/code]

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:
[code]Sprite: myscale<1.0
---> Sprite: set myscale to min(self.myscale + 0.9*dt, 1.0)
---> Sprite: set scale to myscale[/code]

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
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Tue Nov 12, 2013 8:51 am

@R0J0hound

In the Manual under Sprite Actions is the action to Set Scale. Is this not what the OP is looking for?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,388
Reputation: 58,458

Post » Tue Nov 12, 2013 4:15 pm

@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.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Tue Nov 12, 2013 6:42 pm

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

[QUOTE=LittleStain] 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[/QUOTE]
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.

B
4
Posts: 25
Reputation: 302

Post » Tue Nov 12, 2013 6:54 pm

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: http://bit.ly/1anBGNs

Anyway, it's working satisfactorily right now.moiremusic2013-11-12 20:35:54
B
4
Posts: 25
Reputation: 302

Next

Return to How do I....?

Who is online

Users browsing this forum: evillair, gamecorpstudio, jorgmaquoi and 14 guests