Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
lag/delay on a movieclip animation first play — Gideros Forum

lag/delay on a movieclip animation first play

jimlevjimlev Member
edited April 2013 in General questions
Hi !
Another newb question. :-S
I'm using movieClip to add some FX when the player touches some items of my game.

I have a lag problem (only on device) on the first touch event. The animation takes something like 0.5s to display. After that, everything is ok.

Is there a way to "preload" the graphic elements and avoid that delay ?

thks
My meditation plan :
SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
Totebo: “ Best quote ever.”
🤔

Comments

  • talistalis Guru
    edited April 2013
    i suggest that you created "init.lua" file and load all your assets there.
    So it will be loaded before and your animation will work without delay. :D

    "init.lua" is a special file that gideros will automatically run that file before every lua file.

    If you have so many asstes to load you can even create a preloader image like described in this tread.

    http://www.giderosmobile.com/forum/discussion/comment/9755
  • ar2rsawseenar2rsawseen Maintainer
    @jimlev is there a chance you are also simultaneously using sound effect with animation?

    And yes preloading graphics can also help. Usually I create a texture pack with all the graphics needed for specific scene. Then I load the pack when scene loads, thus all graphics will be preloaded before using them :)
  • first of all, thank you for your help.

    I'm trying to produce a basic example to show you my problem.

    @ar2rsawseen: I'm not using Texture Packer. As I'm familiar of graphics software, I'm using sequences of images. I'm going to try Texture Packer to see if I obtain better efficiency

    I have created a specialFX class. In the specialFX.lua, I have lot of framelists (which are sequences of 25-30 png files each).
    How can I preload these files ? What is the code I need ?

    Sorry, I'm really novice with all of that (and have to explain in english doesn't help)

    thx
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
  • ar2rsawseenar2rsawseen Maintainer
    @jimlev if you are using MovieClip, then you probably do something like:
    local frame = Bitmap.new(Texture.new("someimage.png", true))
    --and then create movie clip
    Preloading would be loading the texture somewhere before you even mean to use the movie clip as in
    local texture = Texture.new("someimage.png", true)
    And then when you need it reusing same texture.
    local frame = Bitmap.new(texture)
    --and then create movie clip
    You can store textures in a table as a property of your scene class or global table, etc ;)

    Likes: jimlev

    +1 -1 (+1 / -0 )Share on Facebook
  • thanks a lot ar2rsawseen !

    Here is an example project to show my problem.
    Though I created it from scratch using part of Gideros examples, it shows my delay problem (only on device).

    When you touch the screen for the first time, the animated mc takes something like 0.5s to be displayed. Next instances don't have the lag pb.

    While making that simplified example, I also note that my first instance stop looping when the second one is created... I really think I still have a lot to learn...
    rar
    rar
    mcProject.rar
    337K
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
  • ar2rsawseenar2rsawseen Maintainer
    @jimlev do you experience the same, if you put the line:
    local mySprite = AnimatedSprite.new(s1)
    outside the Touch function like that:
     
    local mySprite = AnimatedSprite.new(s1)		-- create my FX looping animation (s1 parameter is for sequence1)
     
    function onTouch()
     
    local mcAnimatedSprite = MovieClip.new{		-- make a movieclip using my previously created looping animation
    		{1, 70, mySprite, {y = {0, 320, "inSine"},redMultiplier ={1, 0}}},
    		{71, 100, mySprite, {y = {320, 0, "inSine"}}}}
     
    mcAnimatedSprite:setGotoAction(100, 2)		--	make it loopng
     
    mcAnimatedSprite:setX(math.random(100))		-- randomize X position to separate instances
     
    stage:addChild(mcAnimatedSprite)
     
    end
     
    stage:addEventListener(Event.TOUCHES_END, onTouch, stage) 	-- event to launch the f$#*% craps
    Because in this case, the texture will be preloaded on application start, and should be played momentarily on click (because they should already be in memory).

    The same effect is from packed textures :)

    Likes: jimlev

    +1 -1 (+1 / -0 )Share on Facebook
  • Yes !
    You're right, it solves the latency problem...
    though, it adds a new problem. :D

    By creating the sprite that way, there are three new issues :
    - the sprite's sequence doesn't start (dis)playing at the first image of the sequence (easily seen with local player at 15fps rate)
    - all instances of the sprite are synchronised (same images of the sequence are displayed at the same enterframe event)
    - everytime the event is triggered, all the instance of the movieclip (mcAnimatedSprite) restart from start

    :(( snif

    but I have to admit you solve the lag pb :-\"
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
  • ar2rsawseenar2rsawseen Maintainer
    @jimlev sorry, but I don't seem to completely understand the new problem as in can't really grasp of how it is related to where textures are created
  • No problemo !
    Really thanks, your help was appreciated.
    I have to learn a lot more, to avoid all the traps I create myself, by lack of knowledge
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
Sign In or Register to comment.