[r168] Anchor Behavior Incomplete

Bugs will be moved here once resolved.

Post » Thu May 08, 2014 2:38 pm

Problem Description
Ok... I know it can be viewed as a feature request more than as a bug per se.
But I choose to report it as a bug because the modification is so small that it looks more like a design oversight than anything else.

So here is the thing:
You can't ask the anchor behavior to just anchor your object vertically OR horizontally, leaving the other axis alone.

In my case, I just wanted a UI element to stick to the left border and keep using its default Y position.
But in some scaling mode (like scale outer) the difference between window border and object position can change. Thus Unecessarily moving the object.

And in any cases, I always wondered why the options between Left, Top, Right and Bottom edge were so inconsistent.


Here is my simple fix:

edittime.js
Code: Select all
@@ -76,8 +76,8 @@
 // new cr.Property(ept_combo,      name,   "Item 1",       description, "Item 1|Item 2|Item 3")    // a dropdown list (initial_value is string of initially selected item)
 
 var property_list = [
-   new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "Window left|Window right"),
-   new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "Window top|Window bottom"),
+   new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "None|Window left|Window right"),
+   new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "None|Window top|Window bottom"),
    new cr.Property(ept_combo,  "Right edge",       "None",             "Anchor the object's right edge.",                  "None|Window right"),
    new cr.Property(ept_combo,  "Bottom edge",      "None",             "Anchor the object's bottom edge.",                 "None|Window bottom"),
    new cr.Property(ept_combo, "Initial state", "Enabled", "Whether to initially have the behavior enabled or disabled.", "Disabled|Enabled")


runtime.js
Code: Select all
@@ -95,7 +95,7 @@
        var bbox = this.inst.bbox;
       
        // Anchor left to window left
-       if (this.anch_left === 0)
+       if (this.anch_left === 1)
        {
            inst.update_bbox();
            n = (layer.viewLeft + this.xleft) - bbox.left;
@@ -108,7 +108,7 @@
        }
       
        // Anchor left to window right
-       else if (this.anch_left === 1)
+       else if (this.anch_left === 2)
        {
            inst.update_bbox();
            n = (layer.viewRight - this.xright) - bbox.left;
@@ -121,7 +121,7 @@
        }
       
        // Anchor top to window top
-       if (this.anch_top === 0)
+       if (this.anch_top === 1)
        {
            inst.update_bbox();
            n = (layer.viewTop + this.ytop) - bbox.top;
@@ -134,7 +134,7 @@
        }
       
        // Anchor top to window bottom
-       else if (this.anch_top === 1)
+       else if (this.anch_top === 2)
        {
            inst.update_bbox();
            n = (layer.viewBottom - this.ybottom) - bbox.top;


(To really really be complete, maybe adding "window left" and "window top" for right edge and bottom edge option, imagining some cases where the object it is assigned to would change size while still be anchored to it's opposite border window... why not? (: )

I could of course fork the behavior... but just for that it would be... sad.

In any case, Ash, don't hesitate to throw this post in another part of the forum if you don't think it should be here =)

Construct 2 Version ID
r168



Edit:
Ok after a bit more fiddling, I realised that the plugin was using the first two edges constraint to position the object and the two last to stretch it... which is highly unintuitive I'd say.
Using my fix, you'd have strange result if you do Top Edge: None + Bottom Edge: Bottom. I thought first that the object's bottom edge would stick to its initial bottom position, but with the current implementation, it will just stretch the object vertically to keep the bottom edge at its initial bottom position.
So ok, it might be a mix of feature request and design/conceptual bug report... A matter of opinion (:
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Thu May 08, 2014 3:12 pm

So it's just a new 'None' setting for the window left/top properties? Seems reasonable, added for next build.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,625

Post » Thu May 08, 2014 3:36 pm

@Yann :

"Ok after a bit more fiddling, I realised that the plugin was using the first two edges constraint to position the object and the two last to stretch it... which is highly unintuitive I'd say."

I agree to this, I know the manual describes it perfectly, but a quick and clearer reminder in the description could be useful I think (even though I guess people are les likely to read the manual to understand it then)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Thu May 08, 2014 5:02 pm

@Ashley
Yup, but keep a critical eye, I didn't thoroughly test all implication this would have with combining all possibilities. But since it's so small it should be ok =)

@Aphrodite
Yeah I'm guilty of not usually checking the manual. I prefer directly go into the plugin's source so I understand everything that occurs under the hood.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 14 guests