equaling the size of sprites

Get help using Construct 2

Post » Thu Oct 03, 2013 11:08 pm

I have my character divided in 2 parts that move together forming the whole animation.

The main part is resized to a certain scale and I need the other part to have the same size.

Since I can't find the exact scale the first sprite has, I guess this must be done with exrpessions, like "everytick, [(EXP)match the size of this sprite to that other sprite]"

Is this true? how would that expression be formed?

thanks!
B
5
S
1
Posts: 92
Reputation: 609

Post » Thu Oct 03, 2013 11:37 pm

Yeah, there is no expression to get a sprite scale, while you can set it (as far as I know, I might be wrong, but I think it's because you can modify height and width separately, so there is not one unique scale). So one way to do it is to store the original width or height of the first sprite in an instance variable when its scale is still 1:1 (like on layout start). Then you can calculate the sprite scale at any time by dividing the current width by the original width.
It would be something like this:

Every Tick -> Sprite2 scale = Sprite1.Width/Sprite1.originalWidth

Not sure if it's the most efficient way, but that should work. There might be a workaround that does not require using variables.OlivierC2013-10-03 23:44:15
B
12
S
5
G
2
Posts: 132
Reputation: 2,637

Post » Fri Oct 04, 2013 12:27 am

Well, finally I was able to solve it myself.

I did it by adding an event at everytick setting the scale of the first sprite at 0.2 (since I found out that was close to the scale I'd chosen initially) and then doing it again with the second one.

voila!
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Oct 04, 2013 11:27 am

Do you need to do it at every tick? Since you set it at a constant 0.2, why don't you just do it once when the layout start? If the scale never change, there is no reason to to repeat it on every tick (unless I'm missing some information). I know it's a simple operation and that it's not significant enough to slow things down, but it's good practice to try to keep things optimize, even for the small things
B
12
S
5
G
2
Posts: 132
Reputation: 2,637

Post » Fri Oct 04, 2013 9:39 pm

I don't know how to apply it as a constant or that. I'll investigate.

I plan to do some zooming at some moment (which I still didn't check how is done), so, if this doesn't interfere with the zoom process then it's fine.
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Oct 04, 2013 10:22 pm

If you need to retrieve an objects scale at certain points, use an instance variable to set the scale.

every tick -> set scale to Self.scale

on trigger -> set object.scale to n

then when you need to retrieve it, get that instance variables value.
B
47
S
14
G
7
Posts: 603
Reputation: 8,161


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], Zzarkz and 29 guests