Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
severe lag with background image — Gideros Forum

severe lag with background image

boriskeyboriskey Member
edited September 2014 in General questions
hi guys, I was testing my game on ipad 3 and noticed severe lags when I am switching scenes. I am user a scene manager.

Turned out it is background images I use for the scenes - if I comment out the section that sets background in scene init class, lags will be gone.

Here is how i set background images:
	local bg = Bitmap.new(Texture.new(packs[self.curPack].mapBGImage,true))
	bg:setAnchorPoint(0.5,0.5)
	bg:setPosition(dxmax/2,dymax/2)
	self:addChild(bg)
My project dimensions are 800x480 and use normal scale images and @2x scale images. On my ipad 3 it would use @2x scale and my bg image dimensions will be 1704x1200 at @2x.

The image itself is jpeg and average size for @2x image is 200-250kb.

Any ideas how to remove this lag? Will TexturePack help in this case? Since images are big I thought they would not make a difference and the pack would be huge.

Comments

  • I noticed a lag in loading full screen images on the iPad 3 as well. Loading that big of an image is going to be slow. The only way around it at this point is to preload it in smaller chunks (e.g. 4 images of 852x600) to avoid freezing up the UI.

    And you might be able to preload only 5 or less images before the garbage collector kicks in.

    Now that the source is open, I may look at loading the image in a different thread if I ever get some free time :).

    Likes: boriskey

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @boriskey as @EricCarr said loading images is synchronous action
    You may preload the bg on game start and keep it in memory (like in global variable) if you need that scene to load quicker.

    What I usually do is dim the screen and display loading text, between scenes:

    http://giderosmobile.com/forum/discussion/3733/implement-loading-scene-/p1

    Likes: boriskey

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbcjdbc Member
    edited September 2014
    I usually load most of textures and sounds using a "preload" function before first scene is loaded. Then I use these textures and sounds.

    Example:
    Scene = Core.class(Sprite)
     
    -- Static function called in main.lua
    function Scene.preload()
      Scene.texture_bg  = Texture.new("gfx/background.png", true)
    end
     
    -- Draw background image
    function Scene:draw_bg()
      local bg = Bitmap.new(Scene.texture_bg)
      self:addchild(bg)
    end

    Likes: boriskey

    +1 -1 (+1 / -0 )Share on Facebook
  • thanks, guys, it helps!
  • so I tried to preload 6 textures and it is super fast now.

    BUT the RAM utilization on iPAD jumped from 60Mb to 130Mb (according to Xcode)

    Is that a bad thing? I am reading that the best practice is to keep RAM utilization around 50-60Mb especially for older devices.

    The wait icon and dimming screen works, but the user experience is not great though since users will see that a lot.
  • jdbcjdbc Member
    edited October 2014
    Use TexturePacker to reduce memory or may be try to preload textures only when you are sure that you need them and reuse a single texture object for background. Usually JPG files are less size than PNG files and they are both ok for background images.

    I guess the best solution will depend on your textures size.
  • I think 130 Mb usage is quite ok currently

    I am reading that the best practice is to keep RAM utilization around 50-60Mb especially for older devices.
    ------->this line must be for older device like iphone 3g,3gs, ipad 1 which are currently not supported so you can ignore that

    Likes: jdbc

    +1 -1 (+1 / -0 )Share on Facebook
  • thanks @hgvyas123. I think so too yet I am still trying to reduce the consumption of RA<.

    I implemented a load image as suggested above by @ar2rsawseen for now, funny thing I 've spent 2 hours picking a nice animated load spinner when I realized that animated load indicator cannot be done in Gideros :)

    I was trying to preload next/previous backgrounds but it still makes things laggy because Gideros cannot load images asynchronously.

    So I am not happy but it is what it is.
  • @boriskey, if your game is a low fps point/click adventure you could divide each background into a grid of smaller jogs that load one by one on a timer, so the game is still interactive while loading. Kind of a fake asynchronous loading. I'm experimenting with this for an upcoming adventure game. On the other hand, I do notice a lot of adventure games have a lag that I get used to steen screens. My iPad mini loads much quicker than my older ipad 3.
  • thanks but in my case it won't make a difference as I need to load everything first, so the lag will still be there.

    good to know about mini - I was actually testing my app on nexus 5 as well and the lag is not that noticeble also.

    BTW I found quite a few old threads from 2012 - people complaining about this, stating that Corona and Cocosx are using much faster libs to load textures and doing this asynchronously. So I guess this was never improved. For some games, it is actually a pretty big deal.

    I also have a couple other games published that use many full screen background images and both native java android code and objective c were handling them quite well with no lags at all. I did use some weak references to cache 4-5 images and free them up dynamically but even then there were no lags even on very old android devices.
Sign In or Register to comment.