love2d ffi 窗口移动

内置的窗口位置函数会重载窗口,于是自己造一个,直接调用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值