0
캔버스가 변형되면 실제 호버를 타일에 표시하려고합니다.캔버스 - 변환에 의한 등각 투영 뷰, 어떤 타일이 마우스인지 확인
렌더링 기능 :
ctx.rotate(Math.PI/4)
에 노력하고 있습니다
ctx.save()
ctx.transform(1, 0.5, -1, 0.5, 250, 150)
// ctx.setTransform(1, 0.5, -1, 0.5, 250, 150)
Terrain.forEach((line, lineNumber) => {
line.forEach((tile, blockNumber) => {
const block = new Block({
...resolveBlock(tile),
position: {
x: blockNumber * 32 + 250,
y: lineNumber * 32
},
size: {
width: 32,
height: 32
}
})
// check if the mouse position is on tile
block.mousePos(frameNow)
block.render()
})
})
ctx.restore()
mousePos 기능
하지만 전체 ctx.transform (...) 또는 ctx.scale (1, 0.5) 시간에 대한
function mousePos() {
let currentX =
mousePos.x * Math.cos(-(Math.PI/4)) -
mousePos.y * Math.sin(-(Math.PI/4))
let currentY =
mousePos.x * Math.sin(-(Math.PI/4)) +
mousePos.y * Math.cos(-(Math.PI/4))
if (
currentX >= this.position.x &&
currentX <= this.position.x + this.size.width - 1 &&
currentY >= this.position.y &&
currentY <= this.position.y + this.size.height - 1
) { // change color of hovered tile... }
}
감사합니다.
가능한 복제 [마우스를 변환하는 가장 좋은 방법은 HTML5 캔버스의 변화 상황에 맞는 좌표 (https://stackoverflow.com/questions/40835163/best-way-to-transform-mouse -coordinates-to-html5-canvass-transformed-context) – AuxTaco
불행히도 운이 좋았지 만, 불행히도 : 어쩌면 나는 그것을 정말로 이해하지 못했을 것입니다. –