动画的性能问题
2013-7-26 15:11:45
收藏:0
阅读:131
评论:1
当我在模拟器上运行模拟器时,一切都很顺利,但一旦我在实际设备上运行我的游戏时,在加载/开始动画时游戏会冻结一会儿。
我不知道我做错了什么。 这是加载动画的代码:
function showAnimation(event, type, index)
if type == "explosion" then
sheetData = { width=100, height=100, numFrames=33, sheetContentWidth=1100, sheetContentHeight=300 }
mySheet = graphics.newImageSheet( "media/animations/Explosion.png", sheetData )
sequenceData = {
{ name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33 }, time=1050, loopCount = 1 }
}
elseif type == "smoke" then
-- 从5个烟雾动画中选择
sheetData = { width=100, height=100, numFrames=23, sheetContentWidth=500, sheetContentHeight=500 }
mySheet = graphics.newImageSheet( "media/animations/smoke-" .. math.random(1,5) .. ".png", sheetData )
sequenceData = {
{ name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 }, time=math.random(555, 1110), loopCount = 1 }
}
elseif type == "fire" then
sheetData = { width=40, height=40, numFrames=89, sheetContentWidth=400, sheetContentHeight=360 }
mySheet = graphics.newImageSheet( "media/animations/fire.png", sheetData )
sequenceData = {
{ name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89 }, time=6000, loopCount = 1 }
}
end
animation[index] = display.newSprite( mySheet, sequenceData )
animation[index].name = type
animation[index].id = index
animation[index].x = event.x
animation[index].y = event.y
animation[index]:rotate(math.random(-360, 360)) -- 随机旋转动画
animation[index]:play()
-- 清除函数
local function mySpriteListener( event )
if ( event.phase == "ended" ) then
-- 清除不可见的火药桶
if invisibleTnt ~= nil and animation[index] ~= nil then
...
end
-- 清除火焰
if flames ~= nil and animation[index] ~= nil then
...
end
if animation[index] ~= nil then
--animation[index]:removeSelf()
animation[index]:getParent():remove( image )
animation[index] = nil
end
end
end
-- 运行清除函数
animation[index]:addEventListener( "sprite", mySpriteListener )
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中获取用户配置主目录的跨平台方法
如果你将要一遍又一遍地使用这些图片,那么我会提前加载它们,然后只在需要时生成雪碧图。这将节省加载图片和解析图片的时间。