Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
[SOLVED]timer = Timer.new(1000, 0) weight — Gideros Forum

[SOLVED]timer = Timer.new(1000, 0) weight

JackoJacko Member
edited March 2015 in General questions
timer = Timer.new(1000, 0)
In my game I want to count many times for my player but after I start about 7 counting condition my game starts stutter so
Is there other function that can repeat condition after one second and its not so hard for the CPU?

Comments

  • @jacko. Can you provide some code. This should work without any issues. It all depends on what you are doing every second.

    Likes: Jacko

    +1 -1 (+1 / -0 )Share on Facebook
  • JackoJacko Member
    after 10 secends when you move camera she starts jams
    7z
    7z
    counting.7z
    979K
  • JackoJacko Member
    I test it on Samsung galaxy grand 2, Lg G3s and Alcatel
  • JackoJacko Member
    edited March 2015
    U need to click hall 15 clouds to start couting
  • Try deleting or commenting out all print statements while testing in real device.

    Likes: Jacko

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    edited March 2015
    @talis, sharing ar2rsawseen's trick with you ;)

    override print function in main.lua when publishing, comment it out to "debug"
      function print() end
    :D

    Likes: Jacko, simwhi, talis

    +1 -1 (+3 / -0 )Share on Facebook
  • JackoJacko Member
    edited March 2015
    You are right, I'm using BMTextField.new(font,tostring(sekundy15)) and thats slow down camera, but In my game I need to print them their times:(
  • piepie Member
    @Jacko I have some issues following your code since names are a bit confusing with my native language :) however I think that you can speed up things optimizing your code:

    1)
    I don't know about BMFont and BMTextfield, but it seems to me that those are replicas of existing gideros core classes: Font and TextField.
    Maybe those are the same exact functions since it seems that init parameters are the same, and there is a reference to those in gideros repo (https://github.com/gideros/BMFont).
    I would try renaming every occurency of BMFont to Font and BMTextField to TextField and remove BM files from the project. - if those are doing the same things, you are loading them twice "for free". :)

    2) Instead of creating a new Textfield everytime you need to place a piece of a string, you can concatenate strings with .. and then place only one TextField on stage.
    local function getMyName()
     return "Conan"
    end
    local str1 = "This is my name: "
    local str2 = getMyName()
    local str3 = " and this is my surname: "
    local str4 = "The Barbarian"
    local allStrings = str1..str2..str3..str4..". Here you can add some more using the same syntax."
     
    print(allStrings)
     
    local txt_field = TextField.new(font, allStrings).
    stage:addChild(txt_field)
    3) I'm not sure how you're doing with textfield management, but if you are adding a new textfield and removing another every time a value is updated you are incrementing the cpu workload with no reason.
    A better approach could be to update existing TextFields using TextField:setText()
    Since you don't need to remove the old ones, the garbage collector is happier. (and garbage collector is "expensive") :)

    4) Try bhLeaky to check what you are leaving behind, could be a pain setting it up (to me it was :) ) but it's totally worth it.
    http://giderosmobile.com/forum/discussion/2645/help-with-memory-leak#Item_18

    Likes: Jacko

    +1 -1 (+1 / -0 )Share on Facebook
  • JackoJacko Member
    I notice that it dont want to remove text from stage its creat another one on previous text
  • piepie Member
    edited March 2015
    if you create every textfield as local I don't think it's overwriting the same textfields: I think it's initializing every time a new local variable bound to a new texfield object. but it's too far from my knowledge of lua to tell - and I can't reverse engineer your code :) . I may be wrong, but using setText() at least let you save up resources on textfield creation.

    What I know is that you should be able to manage more than all your timers and textfields without all this suffering from the cpu.

    Likes: Jacko

    +1 -1 (+1 / -0 )Share on Facebook
  • JackoJacko Member
    Thank you very much @pie Its working with TextField:setText() :)
Sign In or Register to comment.