Tilemap - changing scale returns wrong PositionToTile

Bugs will be moved here once resolved.

Post » Wed Sep 10, 2014 11:51 pm

Problem Description
When the layout/layer scale is different from 1 the PositionToTile expression returns wrong tile index.

Attach a Capx
bug-tilemap-position-to-tile-01.capx


Description of Capx
A tilemap that is drawn when the mouse is pressed.

Steps to Reproduce Bug
  • 1 - Preview the capx
  • 2 - Click and Drag to draw tiles
  • 3 - Observe results
  • 4 - Disable first event and repeat steps 1 to 3

    Observed Result
    The mouse position and the tile positions do not match when the layout/layer scale is changed.

    Expected Result
    Mouse and tile positions should match.

    Affected Browsers
    • Chrome: YES
    • FireFox: YES
    • Internet Explorer: not tested

Operating System and Service Pack
Windows 7 32bits

Construct 2 Version ID
r179
You do not have the required permissions to view the files attached to this post.
Scirra Employee
B
152
S
53
G
17
Posts: 711
Reputation: 17,800

Post » Thu Sep 11, 2014 7:13 am

Use MouseX(0) and MouseY(0) (or MouseX("Layer 0") and MouseY("Layer 0")) instead of MouseX and MouseY. This is not a bug, this is a feature.
B
11
S
2
G
1
Posts: 25
Reputation: 1,685

Post » Thu Sep 11, 2014 4:48 pm

@onurdogan07 is right - you need to pass a layer parameter to the expressions for scaling to be taken in to account.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Thu Sep 11, 2014 5:20 pm

While this makes sense for a single layer scaled, I don't think it's an expected behavior for changing the layout scale.

The MouseX and MouseY should return layout coordinates scaled according to the layout, as the manual states:
X
Y
Return the position of the mouse cursor in game co-ordinates. This is (0, 0) at the top left of the layout. It changes to reflect scrolling and scaling. However, if an individual layer has been scrolled, scaled or rotated, these expressions do not take that in to account - for that case, use the layer versions below.


As the manual describes, the specified layer positions MouseX(0) should be only used when a single layer has a different scaling than the others, otherwise MouseX should cover it.

So it doesn't seems to be a problem with tilemap's PositionToTile, but the MouseX and MouseY not accounting for layout scaling.
@Ashley Shouldn't it account for?
Last edited by Animmaniac on Thu Sep 11, 2014 6:32 pm, edited 1 time in total.
Scirra Employee
B
152
S
53
G
17
Posts: 711
Reputation: 17,800

Post » Thu Sep 11, 2014 5:59 pm

Maybe have it default to whatever layer 0 is.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Fri Sep 12, 2014 2:37 pm

Oh, you're right - the X and Y expressions were supposed to take in to account the layout scale, but the code was wrong. It should be fixed in the next build for both Touch and Mouse, and layout scale and angle, if you don't pass a layer.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 6 guests