[Question] Anchor Behavior VS Manual Placement

0 favourites
  • 4 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi there, I have a question about relative placement of sprites using the anchor behavior.

    I think that there are 2 ways to relatively align objects to the viewport of a game:

    1. The Anchor Behavior

    2. Manually placing the sprites X & Y positions by using the Viewport Expressions. [eg. ViewportLeft("Layer") + ViewportRight("Layer")) / 2 , to center X]

    However, if we for example plan to create a simple game menu with a sprite in the center and use the anchor behavior to do that, wouldn't that be inefficient

    compared to manually placing the sprites X position with the viewport expressions at the start of a layout?

    I mean when using the 2nd method you essentially just trigger it once with only one impact on performance on the start of the layout.

    Just to make it clear, I think that the anchor behavior is always setting the position of a sprite.

    Meaning after the sprite had been placed in the correct position in the first time, would it still run and try to set the sprites position even if it has the same value as before?

    For example if we would try to place the relative X position of a sprite, would the behavior work like the following:

    IF: Sprite.X is still at the same place ~> DO: Nothing (No further performance impact.)
    ELSE DO: Set the new position and relatively place Sprite.X[/code:8jwxgv2g] OR does the behavior work like this:
    [code:8jwxgv2g]ALWAYS [Every Tick]: Determine the new position and relatively place Sprite.X (Constant impact on performance.)[/code:8jwxgv2g]
    I know that this might be confusing but it is really difficult for me to explain this process
    because I don't know/understand what goes on behind the scenes, in the actual JS code.
    ([i]I guess this question is for people with experience in coding with JS?[/i])
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Interesting question, and I wish I knew the answer. I suspect that you are right and that Anchor does position objects every frame - could you perhaps disable Anchor behaviour when unneeded? In any case I'd be surprised if the performance benefit in this case was anything other than infinitesimal?

  • I don't know how the anchor behavior works regarding this matter, but I think it sets the positions only if the game was resized and not every tick.

  • In any case I'd be surprised if the performance benefit in this case was anything other than infinitesimal?

    Maybe not on desktop or overall devices with a lot of power but imagine that you'd create a mobile game with ~25 sprites using the behavior at the same time.

    ...could you perhaps disable Anchor behaviour when unneeded?

    guess you could, but isn't the plugin made to simplify the whole process? If I have to do workarounds like these all the time with each sprite, I'd not use the plugin in first place and directly go over to methods with Viewport Expressions.

    I don't know how the anchor behavior works regarding this matter, but I think it sets the positions only if the game was resized and not every tick.

    oesn't this still require a process to check if the viewport had been resized or not? I still see no benefit in using the plugin if that would be the case.

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