Hi,
I’m looking for changing camera pos, but there is a problem.
The game window is smaller than the screen (1920 vs 2560). And the map is… far bigger than the two.
I can move the map easily with the keys. Works well (in the camera script) :
local position = go.get_position()
local zoom = go.get("#camera","orthographic_zoom")
-- moving camera with the keyboard
if action_id == hash("right") then
position.x = position.x + (5 / zoom)
go.set_position(position)
elseif action_id == hash("left") then
position.x = position.x - (5 / zoom)
go.set_position(position)
elseif action_id == hash("up") then
position.y = position.y + (5 / zoom)
go.set_position(position)
elseif action_id == hash("down") then
position.y = position.y - (5 / zoom)
go.set_position(position)
end
When I want to drag the screen with the mouse, I do :
if action.x and action.y then
local pos = vmath.vector3(action.x, action.y, 10)
go.set_position(pos)
end
Work well, too. even with the zoom.
But if I add some condition to the IF, like that :
if action.x and action.y and (action_id == hash("wheelclick") or action_id == hash("e")) then
local pos = vmath.vector3(action.x, action.y, 10)
go.set_position(pos)
end
Then the camera jump at another point, then works correctly. I first tough it could be the zoom, and still think, but it’s pretty hard to say
“e” is used only there.
Any idea how to make it to “not jump” ? And if somebody knew how to separate system and game cursor, it would help me, too.
For ref, here’s the zoom function :
if action_id == hash("wheelup") and self.wheel < 1 then
self.wheel = 1
msg.post("/curseur#curseur", "wheel", {wheel = 1})
zoom_state = zoom_state + 1
if zoom_state > zoom_max then
zoom_state = zoom_max
end
go.set("#camera", "orthographic_zoom", 1*(math.pow(zoom_gap, zoom_state)))
elseif action_id == hash("wheeldown") and self.wheel < 1 then
self.wheel = 1
msg.post("/curseur#curseur", "wheel", {wheel = 2})
zoom_state = zoom_state - 1
if zoom_state < zoom_min then
zoom_state = zoom_min
end
go.set("#camera", "orthographic_zoom", 1*(math.pow(zoom_gap, zoom_state)))
end
And in Curseur.script :
In on_message
if message_id == hash("wheel") then
Wheel_Zoom(message["wheel"])
end
and
function Wheel_Zoom(wheel)
if wheel == 1 and zoom_state <= zoom_max then
wheel = 0
for i, id_instance in ipairs(systeme) do
tmp = lua_lire_systeme(i,"id_instance")
if zoom_state > 5 then
sprite.set_constant(tmp.."#sprite_close", "tint", vmath.vector4(1, 1, 1, 1))
sprite.set_constant(tmp.."#sprite", "tint", vmath.vector4(1, 1, 1, 0))
else
sprite.set_constant(tmp.."#sprite_close", "tint", vmath.vector4(1, 1, 1, 0))
sprite.set_constant(tmp.."#sprite", "tint", vmath.vector4(1, 1, 1, 1))
end
go.set(tmp.."#sprite", "scale.y", 1*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite", "scale.x", 1*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite_close", "scale.y", 0.25*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite_close", "scale.x", 0.25*(math.pow(zoom_gap, -zoom_state)))
go.set("/curseur#sprite", "scale.x", 1*(math.pow(zoom_gap, -zoom_state)))
go.set("/curseur#sprite", "scale.y", 1*(math.pow(zoom_gap, -zoom_state)))
end
elseif wheel == 2 and zoom_state >= zoom_min then
wheel = 0
for i, id_instance in ipairs(systeme) do
tmp = lua_lire_systeme(i,"id_instance")
if zoom_state < 6 then
sprite.set_constant(tmp.."#sprite_close", "tint", vmath.vector4(1, 1, 1, 0))
sprite.set_constant(tmp.."#sprite", "tint", vmath.vector4(1, 1, 1, 1))
else
sprite.set_constant(tmp.."#sprite_close", "tint", vmath.vector4(1, 1, 1, 1))
sprite.set_constant(tmp.."#sprite", "tint", vmath.vector4(1, 1, 1, 0))
end
go.set(tmp.."#sprite", "scale.y", 1*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite", "scale.x", 1*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite_close", "scale.y", 0.25*(math.pow(zoom_gap, -zoom_state)))
go.set(tmp.."#sprite_close", "scale.x", 0.25*(math.pow(zoom_gap, -zoom_state)))
go.set("/curseur#sprite", "scale.x", 1*(math.pow(zoom_gap, -zoom_state)))
go.set("/curseur#sprite", "scale.y", 1*(math.pow(zoom_gap, -zoom_state)))
end
end
-- Signal to camera.script that Cursor changed stuff from zoom
msg.post("/camera", "wheel_retour", {wheel_retour = 0})
end
Edit : Spelling