so i try to use scenemanager, basically movefromright/left, it is ok on desktop, but on tablet it jumps always to the half of the screen and then slides, even in which case there is ugly tearing.
my scenes contain a lot of sprites and i think the problem is that when the scene is loaded already a lot of time have passed.
so how can i make sure that everything is loaded from the scene before starting the transition? i tried to put something at the end of the init function of the scene, so that only when it is reached does the enterframe of the scenemanager start (and it sets the timer to 0 at this point), but that does not help.
Comments
Simply put this inside your init method
although i think my question was not clear, you encouraged me to start/stop touch and enterframe events upon enterEnd/exitBegin, which was necessarry anyway. as it did not stop the transition from lagging, i had the idea that maybe testing on device is not only different because of the computing power, but also screen size.
so the solution turned out to be:
in sceneManager transitions are computed from getContentWidth whereas i needed getDeviceWidth as my project is not scaled.
i changed all occurrences of getContentWidth to getDeviceWidth in the transition functions of sceneManager and now it works quite as i would expect.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
"although i think my question was not clear, you encouraged me to start/stop touch and enterframe events upon enterEnd/exitBegin, which was necessarry anyway. as it did not stop the transition from lagging, i had the idea that maybe testing on device is not only different because of the computing power, but also screen size.
so the solution turned out to be:
in sceneManager transitions are computed from getContentWidth whereas i needed getDeviceWidth as my project is not scaled.
i changed all occurrences of getContentWidth to getDeviceWidth in the transition functions of sceneManager and now it works quite as i would expect."
accept now it is your answer
btw still when i first transition to a scene it usually happens that it appears mostly without transitioning, i think again because loading and creating the assets of the scene takes too much time in itself. the second time i transition into it, it works smoothly.
so maybe it is a good idea to preload the assets of all scenes of the menu system at the very beginning (i have two a 2-page menu e.g.), i will experiment with that, maybe it will help first transitioning experience.
Dislikes: pm1891
Fragmenter - animated loop machine and IKONOMIKON - the memory game
for that i added the following changes to scenemanager:
in changescene function i changed the respective part to:
if not self.preloaded or self.scene2==nil then
self.scene2 = self.scenes[scene].new(options and options.userData)
self.scene2:setVisible(false)
end
self:addChild(self.scene2)
self.preloaded=false
and i added:
function SceneManager:preload(scene,options)
self.scene2 = self.scenes[scene].new(options and options.userData)
self.scene2:setVisible(false)
self.preloaded=true
end
and i added at the end of my first scene's init function:
sceneManager:preload("myNextScene")
the problem with this is that you need to know in advance what will be the next scene. of course you can change the code more to preload any/all scene(s), which i did in another project, yet i wonder if there would be any better way to check when the assets are loaded and start transitioning only after that? that would save the overhead of loading many scenes into memory.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i think following trick will work
this way the assets in init function will be preloaded. or? (i would think that if normal functions are executed sequentially (next line of code called when previous finished)
then we should process the second line of code after a scene.new only when init function ended loading assets.
but then it is actually like this in scenemanager as in scenemanager.lua the timer reset to 0 is called only after the scene2.new line, so it should work as efficiently (and it is not efficient, first loading skips transitioning when too many assets) as your proposed trick (which i did not try). am i wrong?
or maybe onenterframe of scenemanager should be removed/added inside the change function so that the above works as we would like? but again, tweening is set to on only after the scene2.new line, so this should not matter.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i tried to put my
sceneManager:preload("myNextScene")
line right before the changeScene line, which should be basically equivalent to your trick, except that instead of loading the assets directly it runs the init function of the next scene, which loads the assets.
yet when doing this way there is the usual skip of transition the first time. in any case i stick to preloading way before changescene will be called, if there is any better solution, let me know.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
resources. it has nothing to do with scenemanager.
[edit]
with few ms of pause before transition get start if there are much resources
also, as i said, i did not try word-by-word your example as i have all the assets loaded upon init of that scene and all of them are called self.something, so putting all this loading into another function which is independent of my class would be a lot of rewriting. that's why i try your idea basically in the following way (by changing scenemanager as i said):
line1: scene2.new --loads all the assets
line2: changescene(to scene2) --does only the transition, without making new scene2
i think this should be equivalent to your trick.
also, i did not put the few ms pause inbetween the two lines, of course that should help, but is not a very efficient way as how could i guess how much time my preload needs on some specific machine? of course one can expect that it is not more than a few secs.
if i will have more time and need i may try to try your trick verbatim, in hope it works differently, but now i don't have time for that.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
also, when i meant that we know in advance the next scene, i meant that we know next scene (scene2) already when entering current scene (scene1) - and so we can preload it already at this time -, which is not always the case. of course right before changing to scene2, we know what is scene2: )
Fragmenter - animated loop machine and IKONOMIKON - the memory game
line2: changescene(to scene2) --does only the transition, without making new scene2"
yup i also think it is similar method
ohhh and i had not said to put any delay actually sentence above is just one line as you are loading the assets and then calling transitions it will automatically put some delay over here according to this rule "next line of code called when previous finished"
now if only we knew how can we make sure that
"next line of code called when previous finished"
concept works 100% (i.e. gideros loads all assets in line 1 and THEN processes line2), as now this is not the case for me.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
instead of putting this line into init (of SceneManager):
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
we should put it into changeScene let's say right after the line:
self:addChild(self.scene2)
also, we would remove this listener after transition ends by putting this line into onEnterFrame let's say after the line:
dispatchEvent(self.scene2, "enterEnd")
we should add:
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
i think this would improve much the smoothness of transitions of scenemanager, without the need of any preloading. also when there is no transition then it is quite unnecessary anyway to have an enterFrame listener that is granted to do nothing at all.
what's your opinion? i did not test it thouroughly, but in practice it also seems like improving the visual feeling of transitions a lot.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I don't know right now what happens, if onEnterFrame is not defined in scene, etc. Will check it.
But of course meanwhile you can clone SceneManager version here:
https://github.com/gideros/Scene-Manager
And provide your own version for community
About this:
"I don't know right now what happens, if onEnterFrame is not defined in scene, etc. Will check it."
I don't understand this, the onenterframe etc i wrote about are all for the scenemanager object and not for the scenes themselves. and as far as i've seen it is indeed only doing anything if self.tweening is true, i.e. there is a transition going on. (actually with adding/removing onenterframe, this tweening variable seems to be not necessary at all).
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
please help, i'm still struggling with this transition.
so is there really no way to start transition only when all the textures are loaded/bitmaps are generated etc in the init function of the next scene?
theoretically if the code processing is sequential, this would be good, but it is not working as i would expect.
(in scenemanager i first make the new scene and only after that i add an eventlistener to do the transition, so it should work good but it does not)
either proper sequential processing or a function like 'isloaded' for textures,bitmaps would solve the issue.
because now the loading slows down the machines and transition is stuttering. the only other workaround would be to add some waiting time after loading the scene and before starting transition, but that's just stupid, the time needed would vary a lot along different phones, so either i set it low and then there is still stuttering on slow phones, or i set it high and then even on fast phones people have to wait a lot before the level begins.
loading all textures and bitmaps for all levels at the beginning of the game seems to be not feasible, especially that the textures i need differ a lot along levels, altogether 1-2 hundred 512x512 textures, loading all of them to the memory seems to be too much, isn't it?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
The quick and dirty fix to load textures before and only after to transition is to delay the transition using Timer, likes this:
i don't understand one concept i think so i'm not sure if:
is this method good for phones of all speed or just for the ones where scene loading stays below 1sec?
edit: it would be 1 millisec, so i assume that it should work on all phones. it seems the point is to force that the things inside the delayed function will happen at least 1 enterframe later.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
is it working for you?
I've used this trick to show Loading element when transitioning between scenes in new Mashballs update. It's very useful on slower phones, because then user gets immediate response from the click on button and is aware that something is happening
showing a small 'loading' sprite in some corner while loading is a good idea.
Fragmenter - animated loop machine and IKONOMIKON - the memory game