Giter Club home page Giter Club logo

Comments (2)

mfessenden avatar mfessenden commented on June 6, 2024 1

Looks like I need to rework the TiledLayerObject.coordinateForPoint method.

The reason for this is because of the difference in coordinate systems between SpriteKit and Tiled. Internally, the conversion between screen points & tile coordinate is happening in Tiled's coordinate space, and converted by the coordinateForPoint & pointForCoordinate methods.

If the point (in SpriteKit coordinate space) is (216.0, -24.0), the floor operation incorrectly returns 2 because floor(-24.0 / 16.0) returns -2 and floor(24.0 / 16.0) returns 1.

Modifying this code will give you the correct result:

    open func coordinateForPoint(_ point: CGPoint) -> CGPoint {
        let coordinate = screenToTileCoords(point.invertedY)
        return floor(point: coordinate)
    }

I'll run a few tests to make sure everything checks out, and push up a fix.

from sktiled.

AUDevs avatar AUDevs commented on June 6, 2024

for now it works. thanks for the awesome framework!
Edit: invertedY is not good. if pixelY is 24 it would be -24 and we have the same problem again.
if (pixelY < 0) {pixelY += 16} fixes my Problem

from sktiled.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.