Here’s some of my code to illustrate what I’m doing… This function adds an image to an object, and repeats 64 times. Immediately after, it tweens the images’ scale to 100%. There are 6 small pngs that are randomly loaded and placed in these objects.
The very first time this happens, there is some stuttering, as in, the framerate drops and it doesn’t look smooth. Once gameplay commences, and this function repeats again, and various images have been removed and nil’d, it looks really smooth.
I’ve read the docs from Ansca staff that it’s good to “lazily” load assets when you need them.
function addMCsToItems()
local hasNewItems = false
local currentSlot = {}
local newMCTable = {}
local i = 0
for i = 1, #mBoardSlots do
if mBoardSlots[i] ~= nil then
currentSlot = mBoardSlots[i]
local itemReference = mBoardSlots[i].boardItem
if itemReference ~= nil then
if itemReference.MC == nil then
local itemPicName = itemReference.itemPicName
local itemPic = display.newImageRect( itemPicName, 40, 40 )
itemPic.xScale = 0.1
itemPic.yScale = 0.1
local itemMC = display.newGroup()
itemMC:insert( itemPic )
mBoard:insert( itemMC )
newMCTable[#newMCTable+1] = itemMC
hasNewItems = true
end
end
end
end
-- display items ( tween scale to 100 )
for i = 1, #newMCTable do
local itemPic = newMCTable[i].itemPic
transition.to( itemPic, { time = 200, xScale = 1, yScale = 1, transition = easing.outQuad } )
end
return hasNewItems
end
I’ve tried to cache the images beforehand ( several seconds before addMCsToItems ):
-- Load Images
local loadAssets = function()
local i = 0
for i = 1, #mCompareArray do
mImageArray[i] = display.newImageRect( mCompareArray[i], 40, 40 )
mImageArray[i].isVisible = false
end
end
loadAssets()
This runs as soon as the code is instantiated. It doesn’t seem to help stop the stuttering issue.
All of this occurs in a package that is being required at the start of the app’s main.lua. Is the fact that it’s in a package being required have anything to do with it?
Moreover, what I’d love to know is a good preloading strategy, and to be able to show a preloader bar, much like how Alien Horde displays when it is first launched.
Any help would be appreciated. Thanks!
Mike [import]uid: 4454 topic_id: 2327 reply_id: 7153[/import]