[Question] Anchor Behavior VS Manual Placement

Discussion and feedback on Construct 2

Post » Sun Apr 17, 2016 6:56 am

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:
Code: Select all
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
OR does the behavior work like this:
Code: Select all
ALWAYS [Every Tick]: Determine the new position and relatively place Sprite.X (Constant impact on performance.)

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 guess this question is for people with experience in coding with JS?)
ImageImageImage
B
69
S
24
G
78
Posts: 694
Reputation: 45,328

Post » Sun Apr 17, 2016 8:22 am

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?
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 209
Reputation: 3,476

Post » Sun Apr 17, 2016 1:40 pm

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.
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,797

Post » Sun Apr 17, 2016 4:48 pm

mikehive wrote: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.

mikehive wrote:...could you perhaps disable Anchor behaviour when unneeded?
I 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.

glerikud wrote: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.
Doesn'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.
ImageImageImage
B
69
S
24
G
78
Posts: 694
Reputation: 45,328


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests