Scirra / Construct-feature-requests

A place to submit feature requests and suggestions for Construct.
https://www.construct.net
11 stars 1 forks source link

layerToCanvas() and canvasToLayer() in scripting #332

Closed F3der1co closed 2 months ago

F3der1co commented 2 months ago

Reviewed guidelines

Checked for duplicate suggestions

Summary

Please add CanvasToLayer(layer, x, y, layerZ) and LayerToCanvas(layer, x, y, z) to the scripting api. I wanted to implement in a game for performance reasons, while looking at the internal implementation I had to go many methods deep and it seems to have quite a lot of complexities I am not understanding full.

Possible workarounds or alternatives

there is probably a way to implement it ourselves, but it seems fairly complex and also it seem to require some stuff that is not easily accessible

Proposed solution

CanvasToLayer(layer, x, y, layerZ = 0) and LayerToCanvas(layer, x, y, z = 0) imo it should return [x, y] so no x and y variants are need. Z should be available but optionally.

I guess it could also be ILayer.ToCanvas(x, y, z = 0) or similar, whatever you feel makes the most sense.

Why is this idea important?

This is useful for a wide variety of cases, for example world to hud position transforms. Implementing a util function ourselves for this seems highly complex and riddled with edge cases.

Additional remarks

No response

F3der1co commented 2 months ago

I didn't look in the right place, seems to already be supported