for循环帮助和精灵添加
2014-5-13 18:3:15
收藏:0
阅读:70
评论:3
我有两个问题。我想要做的是每次射击敌人/藤蔓都应该被移除,并且会发生爆炸。移除可以完美工作,但精灵没有被调用来爆炸。
1.循环中的 `#sectInt.int[“vines”]是什么? 它们是父/子引用吗?有人能详细解释一下这个符号吗?
2.如何在每次摧毁藤蔓后使用我的爆炸精灵? 我很难弄清楚如何在循环中调用每个 x 和 y 的藤蔓在删除时爆炸。
代码:
local sections = require("sectionData")
local lastSection = 0
function createSection()
--创建一个随机数。如果它和上一个相等,就再次随机。
local sectInt = mR(1,#sections)
if sectInt == lastSection then sectInt = mR(1,#sections) end
lastSection = sectInt
--从sectionData文件中获取一个随机部分,然后
--循环创建具有正确属性的所有内容。
local i
-- 屏幕上藤蔓的随机创建
for i=1, #sections[sectInt]["vines"] do
local object = sections[sectInt]["vines"][i]
local vine = display.newImageRect(objectGroup, "images/vine"..object["type"]..".png", object["widthHeight"][1], object["widthHeight"][2])
vine.x = object["position"][1]+(480*object["screen"]); vine.y = object["position"][2]; vine.name = "vine"
local rad = (vine.width*0.5)-8; local height = (vine.height*0.5)-8
local physicsShape = { -rad, -height, rad, -height, rad, height, -rad, height }
physics.addBody( vine, "static", { isSensor = true, shape = physicsShape } )
end
end
-- 爆炸精灵
options1 =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet1 = graphics.newImageSheet( "images/explosion.png", options1)
playerSprite1 = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
explode = display.newSprite(playerSheet1, playerSprite1)
explode.anchorX = 0.5
explode.anchorY = 1
--player:setReferencePoint(display.BottomCenterReferencePoint)
-- 我希望引用循环位置,如果他们都被删除,那么就会播放精灵
explode.x = "vine.x" ; explode.y = "vine .y"
explode.name = "explode"
explode.position=1
extraGroup:insert(explode)
点赞
用户869951
当该葡萄藤要爆炸时,您可以播放精灵动画。如果要爆炸所有葡萄藤,则可以使用以下代码:
sheetOptions =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet = graphics.newImageSheet( "images/explosion.png", sheetOptions)
spriteSequence = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
for i, vine in ipairs(objectGroup) do
local explode = display.newSprite(playerSheet, spriteSequence)
explode.anchorX = 0.5
explode.anchorY = 1
explode.x = vine.x
explode.y = vine.y
explode.name = "explode"
explode.position=1
explode:play()
extraGroup:insert(explode)
end
注意:此代码未经测试,请让我知道任何您无法解决的问题。
2014-05-13 18:16:43
用户3298518
好的,以下是我为了解决任何人都遇到的爆炸问题而做的事情。
``` function isShot(event) print('shot!!!') if(event.other.class ==“enemy”)then 如果(event.other.name ==“limitLine”)then event.target:doRemove()-如果击中limitLine,请删除子弹
else if(event.other.name ==“vine”)then
event.other:doRemove()
spriteExplode(event.other.x,event.other.y)-此函数调用自己并运行精灵
if event.other.name ==“vine” then
if event.other.name ==“explode” then
event.other:doRemove()-这将删除爆炸精灵
end
end
end
-删除子弹和爆炸精灵
定时器.performWithDelay(5000,function(event)explode:doRemove();end,1)
event.target:doRemove()
end
返回真实
结束
function spriteExplode(x,y)
爆炸。isVisible = true 爆炸:播放() print(“播放爆炸”)
如果(x和y)则此代码使我的精灵在删除藤蔓后保持更新
爆炸。x,爆炸。y = x,y
结束
function explode:doRemove(event)
定时器.performWithDelay (
1,
function(event)
显示删除(自己)
自我=否
结束,
1 )
结束
结束
我将isShot函数事件侦听器添加到了Bullet函数中 子弹:addEventListener(“collision”,isShot),同时子弹函数中还有一个子弹:doRemove函数。 希望这可以帮助。
2014-06-19 20:37:24
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的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中获取用户配置主目录的跨平台方法
对于循环中的 #sections[sectInt]["vines"] 这是什么意思?它们是父/子引用吗?有人能详细解释一下甚至告诉我 # 是什么意思吗?
正如我在评论中所说,
#表示[表长度](http://www.lua.org/manual/5.1/manual .html#2.5.5)该循环遍历所选择的片段数据中“藤蔓”数据的每一位(在游戏方面确切地表示什么),然后创建那些藤蔓的对象。