触摸功能不起作用。
2015-11-25 20:23:29
收藏:0
阅读:65
评论:1
我正在尝试在我的iPad上的Codea中创建一个简单的应用程序,用于显示图像并让用户移动它。我能够正确地显示图片,但无法用手指移动它。
以下是我的代码。
function touched(touch)
local currentTouchPosition = vec2(touch.x,touch.y)
if (touch.state == BEGAN) then
end
if (touch.state == MOVING) then
if ((imagePosition.x - imageSize.x/2) < currentTouchPosition.x and
(imagePosition.x + imageSize.x/2) > currentTouchPosition.x and
(imagePosition.y - imageSize.y/2) < currentTouchPosition.y and
(imagePosition.y + imageSize.y/2) > currentTouchPosition.y ) then
imagePosition = currentTouchPosition
end
end
if (touch.state == ENDED) then
end
end
我应该如何使它工作?...提前感谢。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
我猜你现在已经找到了答案,但如果你还没有,我希望这能帮到你。
不确定你在setup()或draw()中做了什么,但我所做的是定义了imageSize和imagePosition作为vec2,并给它们一个初始值。我还添加了一个简单的图像。
除了在touched()中稍微格式化代码之外,代码看起来很好。
我希望以下代码是有意义的。
function setup() -- 屏幕中心 X = WIDTH/2 Y = HEIGHT/2 imageDims = 100 -- 定义图像大小 imagePosition = vec2(X,Y) -- 在setup()中将imagePosition和imageSize定义为vec2 imageSize = vec2(imageDims,imageDims) end function draw() background(40, 40, 50) sprite("Cargo Bot:Codea Icon", imagePosition.x,imagePosition.y, imageSize.x,imageSize.y) end function touched(touch) local currentTouchPosition = vec2(touch.x,touch.y) if (touch.state == BEGAN) then end if (touch.state == MOVING) then if ((imagePosition.x - imageSize.x/2) < currentTouchPosition.x and (imagePosition.x + imageSize.x/2) > currentTouchPosition.x and (imagePosition.y - imageSize.y/2) < currentTouchPosition.y and (imagePosition.y + imageSize.y/2) > currentTouchPosition.y) then imagePosition = currentTouchPosition end end if (touch.state == ENDED) then end end