This problem of mine is rather complicated to explain but I'll try as hard as I can.
I am currently developing a map editor for my little RPG game.
The map editor currently supports a camera and zoom(scale).
What I am currently working on, is the map editing system which should be dependent on camera position and camera scale(zoom), however.. IT DOES NOT WORK AHH
What I want my code to do:
1. It gets user mouse position.
2. It translates the position to a usable value(like [1, 1] or [26, 13]) using camera position(camera.x, camera.y) and zoom(camera.scale)
3. It uses translated data to draw a "selection quad" and for future editing purposes.
What It does:
1. It gets user mouse position.
2. It translates the position to a usable value.
-- logic error?
3. It uses translated data to draw a (bugged out) "selection quad" and for future editing purposes.
Additional Details:
1. It works perfectly fine if the scale is 1(block size is 32px*32px)
2. Here is the code used to translate the mouse input to usable information.
Code: Select all
function edit:getMousePosition()
-- translates data
local x = math.floor((mouseX - camera.x) / (32 * camera.scale))
local y = math.floor((mouseY - camera.y) / (32 * camera.scale))
-- updates values ONLY if they are within the map width/height
if x >= 0 and y >= 0 and x < maplist[map.current].totalX and y < maplist[map.current].totalY then
edit.x = x
edit.y = y
end
end
4. Do not try to read code in the love file from other files except src/edit.lua. (uncommented and hard to understand)
5. You can open an ingame console by pressing f1 and input lua commands by pressing f2.
6. The translation seems to be dependent on camera position and not on camera scale.
7. Thank you for your help