- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在场景中拖动重力 = 0,0 的动态主体,我有一个主体类型为动态的正方形,以及一个主体类型为静态的图像,但是当将方形拖动到图像上时,会出现一个力量不大,但可以超出图像并传递到另一边,如图所示:
这是我拖动方 block 的代码:
local function dragBody( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if "began" == phase then
stage:setFocus( body, event.id )
body.isFocus = true
body.tempJoint = physics.newJoint( "touch", body, event.x, event.y )
elseif body.isFocus then
if "moved" == phase then
body.tempJoint:setTarget( event.x, event.y )
elseif "ended" == phase or "cancelled" == phase then
stage:setFocus( body, nil )
body.isFocus = false
body.tempJoint:removeSelf()
end
end
return true
end
这是创建对象的代码:
function scene:createScene( event )
local group = self.view
my_square = display.newImage("square.png")
my_square.x = 60
my_square.y = 60
physics.addBody(my_square, "dynamic" )
group:insert(my_square)
floor = display.newImage("piso.png")
floor.x = 160
floor.y = 240
physics.addBody(floor, "static" )
group:insert(floor)
end
感谢您的帮助。
最佳答案
首先,我建议您尝试:
physics.setContinuous( false )
如果您已经这样做了:
Physics2D 引擎中有 3 种不同的物理类型。出于拖动目的,您可以使用“运动学”对象类型。但如果必须使用动态对象作为可拖动对象,则可能会出现碰撞错误。但如果你的静态对象每次都是一样的,你可以通过拖动功能来控制它。
我已经实现了一个小手机游戏,使用与你想要实现的相同的东西。链接在这里: https://itunes.apple.com/tr/app/bricks-world/id602065172?mt=8
如果您认为您想要在这个游戏中获得类似的东西,请发表评论^^我可以进一步提供帮助。
P.S:在游戏中, Controller 桨是动态的,屏幕周围的墙壁是静态的。
另一个解决方案:
local lastX, lastY
local function dragBody( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if "began" == phase then
stage:setFocus( body, event.id )
body.isFocus = true
lastX, lastY = body.x, body.y
elseif body.isFocus then
if "moved" == phase then
-- You can change 1's with another value.
if(event.x > lastX) body.x = body.x + 1
else body.x = body.x - 1
if(event.y > lastY) body.y = body.y + 1
else body.y = body.y - 1
lastX, lastY = body.x, body.y
elseif "ended" == phase or "cancelled" == phase then
stage:setFocus( body, nil )
body.isFocus = false
end
end
return true
end
关于lua - corona sdk中拖动物理对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20716394/
由于某些原因,如果 else 语句执行太多次,下面的代码会抛出堆栈溢出错误。我试图让 scene.targeting 函数从参数中传递的 objTable 中选择一个目标,但只有带有 .tgtFlag
我希望使用Corona sdk来开发一款新游戏。但我找不到播放mp3文件的api。Corona sdk支持播放mp3流吗? 欢迎大家留言 最佳答案 实际上,media.playSound() 已被弃用
我为 Corona SDK 构建了以下应用程序 local hello = "hello"; print(hello); 使用 iPhone 作为目标..最终的二进制文件大小达到惊人的
我尝试在场景中拖动重力 = 0,0 的动态主体,我有一个主体类型为动态的正方形,以及一个主体类型为静态的图像,但是当将方形拖动到图像上时,会出现一个力量不大,但可以超出图像并传递到另一边,如图所示:
我目前正在使用Corona SDK开发一款小游戏。我最近开始在游戏中添加音频/声音-fx。所有音频都可以在模拟器,PC和平板电脑上正常工作。但是,当我在Galaxy s7上玩游戏时,音频根本无法执行任
我目前正在制作一个非常简单的应用程序,在该应用程序中,点击图像时会播放声音,某些文本会记录点击次数。但是,我注意到音频中存在一些明显的延迟,在单击图像后,音频将需要半秒钟才能播放。有谁知道为什么会这样
我在模拟器中遇到此错误: main.lua:24:audio.loadSound()无法创建声音“1.wav” 声音正确无误 这是我的代码: (我已经更改了声音的名称和本地名称,但没有用) 我在这里有
我想使用 Corona SDK 制作一个声音合成器,这意味着在纯 Lua 中。所有的 Lua synth 程序都依赖于一个底层的 C 程序。有没有生成波形的Lua库? 最佳答案 我没有音频方面的经验。
好的,我有一个非常非常大的背景图像,不是图像而是蓝色的矩形: bg2 =display.newRect(0,0,20000,20000) bg2.y=10000 bg2:setFillColor( 0
我在 corona sdk 中做了一个简单的游戏。现在我想让它成为一个分屏多人游戏。我想将我的单人游戏用作单元游戏。然后我想在同一设备的两个部分运行两个不同的单元。 但我找不到任何有效的方法来做到这一
我正在用力击球,有一堵墙被分配了物理属性并且是静态的,但球是动态的,问题是当足够的力施加到球上时,它穿过墙,它是简单台球游戏示例中的一种 table 墙。我用过 ball.isBullet=true
我想知道如何使用 Corona 获取图像大小而不加载它们并调用 obj.width。 有办法吗? 最佳答案 如果您的图片是 PNG,是的! http://developer.coronalabs.co
我得到了一张小瓷砖图片。我想用该图像设置背景,我想重复图像以填充整个背景。例如,在 CSS 中,我们使用 repeat-x 和 repeat-y 属性重复背景图像。 最佳答案 你应该得到图像的宽度和高
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。 Improve this
我想知道在为 iOS 构建时,是否有任何原因导致 corona 无法完成“执行构建”。我知道互联网连接不佳(我碰巧没有)会减慢它的速度——但不会达到我需要让我的电脑运行几个小时的程度...... 不久
我想添加自定义方法来显示对象,类似于预建方法,例如“setFillColor” 我写了下面的代码,但没有用;然而,它解释了我需要什么 function display:foo(bar) pri
出于发布原因,这里是我正在尝试做的一个简单版本。 在屏幕上,我有一个简单的圆形对象,它是静态的,不会移动。然后用户可以拖放一条直线。如果这条线穿过那个圆圈,我希望触发碰撞事件。 似乎除非其中一个物体在
我对电晕中的自定义形状有一些麻烦。 这是我的代码,它的作用是我在场景中添加了一些球体,以便它们落入篮子内,这个篮子是我在 newBasket() 函数中定义的自定义形状对象,问题是篮子确实与地面物体碰
我使用 Corona-SDK 制作了一个游戏。它有2个场景:(1)菜单场景和(2)游戏场景。 我需要我的应用程序支持两个方向:“landscapeRight”和“landscapeLeft”。 为此,
我正在制作一个使用物理的游戏。我有一个球,当它到达某个区域时,说 ball.x > 100 and ball.x 100 and ball.y < 110 我希望那个球的线速度减慢,但不要停止。我
我是一名优秀的程序员,十分优秀!