Negative Width for Mirrored Images

Bugs will be moved here once resolved.

Post » Tue Sep 11, 2012 1:22 am

Specs:
Construct 2 r102
Windows 7 64-bit
Intel Celeron

Bug:
When a sprite is mirrored, the width is returned as a negative value. I don't think this is expected behavior.

Example:
Negative Width Capx Sample
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Tue Sep 11, 2012 3:47 am

I think it's intended.. You mirror an object in theory by making it's width -100%.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Tue Sep 11, 2012 11:21 am

This is by design. Mirroring is implemented by inverting the width.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Fri Sep 14, 2012 4:23 am

@Ashley

Hmmm, I'm not sure I agree with this. Width should by definition always be a positive value. Mirroring an image on a 2d plane should have no effect on the actual value. I understand that internally, mirroring may invert the width, but as a property value, width should return the measurement of an object from side to side. It's especially confusing considering that sprite rotation has no effect on the width value.

Since I can't rely on width to return a positive value for any given sprite anymore, and most of the sprite's in my game's visual state is indeterminant, it just means I have to wrap all my Width and Height calls in Math.abs statements.

I can't imagine a situation in a game where you would want to get a negative value for the width of a sprite. I guess you could argue that it lets you tell if a sprite has been flipped/mirrored, but there is already explicit conditional logic in place to check for that.

I spent almost 30 minutes trying to debug a subtle issue that when I finally managed to track it down, it was because width was negative.

B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Fri Sep 14, 2012 6:09 am

Sprite Rotation does not have an effect on the width value because it shouldn't. But open Photoshop and slowly reduce the width of an object, once you reach about 1% width, your object is a thin line and at 0% it's gone, once you reach -1% it's at the opposite/mirrored direction.

This is the same for every software I know, even 3D Modeling software flip the scale of XYZ when you mirror them. -1 Scale in any of these axis gives you a mirrored object.

If you want to use your width in a positive value, simply use abs() as you have stated. It's a little bit tedious, maybe, but trust me, the uses of knowing that your object is mirror through the negative value of the width is a much better and will also fundamentally help you in many ways.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Fri Sep 14, 2012 5:07 pm

We really can't change it, because it would break too many projects that depend on it now.

Also, this used to not be supported, and other users told us they missed it and wished objects would flip or mirror when they go in to negative width or height! So I guess it's a matter of taste or dependent on what you're trying to achieve. Still, changing things causes big compatibility problems and I don't see why we should go through that if it already does the job.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Fri Sep 14, 2012 5:22 pm

[QUOTE=cacotigon] @Ashley

Hmmm, I'm not sure I agree with this. Width should by definition always be a positive value. Mirroring an image on a 2d plane should have no effect on the actual value. I understand that internally, mirroring may invert the width, but as a property value, width should return the measurement of an object from side to side. It's especially confusing considering that sprite rotation has no effect on the width value.

Since I can't rely on width to return a positive value for any given sprite anymore, and most of the sprite's in my game's visual state is indeterminant, it just means I have to wrap all my Width and Height calls in Math.abs statements.

I can't imagine a situation in a game where you would want to get a negative value for the width of a sprite. I guess you could argue that it lets you tell if a sprite has been flipped/mirrored, but there is already explicit conditional logic in place to check for that.

I spent almost 30 minutes trying to debug a subtle issue that when I finally managed to track it down, it was because width was negative.

[/QUOTE]

You can use the mod of the width.
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,211
Reputation: 18,480

Post » Sun Sep 16, 2012 6:14 pm

@TELLES0808: Not sure what you mean by that, modulo division isn't really suitable in this case. Taking the absolute value works fine.

@Ashley: I understand your reasoning, I'm just worried that behaviors, plugins, even collision detection that rely on Sprite.Width/Sprite.Height might suddenly exhibit erratic behavior if the Width/Height could return negative values.

This bug that I just found concerning mirroring/scaling might be related:
Mirroring Scaled Images fails

Do you think I should just create separate animations for mirror/flipped images instead of using mirror/flip?cacotigon2012-09-16 18:14:46
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Sun Sep 16, 2012 6:25 pm

[QUOTE=cacotigon] @TELLES0808: Not sure what you mean by that, modulo division isn't really suitable in this case. Taking the absolute value works fine.

@Ashley: I understand your reasoning, I'm just worried that behaviors, plugins, even collision detection that rely on Sprite.Width/Sprite.Height might suddenly exhibit erratic behavior if the Width/Height could return negative values.

This bug that I just found concerning mirroring/scaling might be related:
Mirroring Scaled Images fails

Do you think I should just create separate animations for mirror/flipped images instead of using mirror/flip?[/QUOTE]

Absolute, that`s the word ^^ mod is how we call it in my language
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,211
Reputation: 18,480


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest