equaling the size of sprites

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

  • Try Construct 3

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

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

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

  • 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

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

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

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