Hey there, I’ve recently tried to implement a movement feature but failed as I couldn’t seem to get online code samples to work.
// PC.js
tileFromPosition (pos, mapLayer) {
var wx = pos.x;
var wy = pos.y;
wx *= cc.view.getScaleX()
wy *= cc.view.getScaleY()
var tw = mapLayer.getMapTileSize().width;
var th = mapLayer.getMapTileSize().height;
var mw = mapLayer.getLayerSize().width;
var mh = mapLayer.getLayerSize().height;
var isox = Math.floor(mh - wy/th + wx/tw - mw/2)
var isoy = Math.floor(mh - wy/th - wx/tw + mw/2 - 1/2)
return { isox, isoy}
},
onLoad () {
this.node.parent.getChildByName('Testing').getChildByName('Floor').on(cc.Node.EventType.TOUCH_END, (c) => {
console.log(this.tileFromPosition(this.node.convertToNodeSpace(c.touch.getLocation()), c.target.parent.getChildByName('Floor').getComponent(cc.TiledLayer)))
})
}
Gives me this:
But the result I’m expecting is { isox: 0, isoy: 0 }
.
Any idea what I am missing? Thanks in advance.