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?
@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.
localfunction getMyName()return"Conan"endlocal 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")
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.
Comments
Likes: Jacko
Likes: Jacko
override print function in main.lua when publishing, comment it out to "debug"
Likes: Jacko, simwhi, talis
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.
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
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