内置的窗口位置函数会重载窗口,于是自己造一个,直接调用winapi就行了。
写的时候可以简化一点,指针都用 void*
即可。
local ffi = require("ffi")
ffi.cdef[[
void* GetActiveWindow();
int GetSystemMetrics(int f);
int SetWindowPos(void *h, int z, int x, int y, int cx, int cy, int f);
]]
local function getResolution()
return ffi.C.GetSystemMetrics(0), ffi.C.GetSystemMetrics(1)
end
local function setPosition(x, y)
ffi.C.SetWindowPos(ffi.C.GetActiveWindow(), 0, x, y, 0, 0, 0)
end
local sin, cos = math.sin, math.cos
local scrw, scrh = getResolution()
local winw, winh = love.graphics.getWidth(), love.graphics.getHeight()
local ox, oy = (scrw-winw)/2, (scrh-winh)/2
local t = 0
function love.update()
t = t+.1
setPosition(ox+200*cos(t), oy+100*sin(t))
end