Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Director class - check this out!
Started by ricardorauber Oct 06 2010 03:20 AM

- - - - -
79 replies to this topic
[TOPIC CONTROLS]
Page 2 of 4 1 2 3 4
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

Everything that is inserted into the group, director will call the remove function while changing scenes but I don't thing that timers works with that. I can't test it right now, but as soon as I can I'll do it.
uid: 8556 topic_id: 2447 reply_id: 7751


[TOPIC: post.html]
#27

awesomeware14

[GLOBAL: userInfoPane.html]
awesomeware14
  • Observer

  • 10 posts
  • Guests

Okay, I'm not sure whether or not it deletes either yet but that would definitely be nice to know. However, that's not the actual problem. When I'm using the timer.performWithDelay function the screen goes black. It is definitely the use of the timer.performWithDelay because I had it call an empty function as a test and it still caused the screen to go black. I've tried it both with and without putting it in a display.newGroup()and with and without giving a variable name. I'll keep trying to figure it out let me know if you need more of the source code once you have time to look at it.

Edit: Okay so I was able to get get the timer.performWithDelay to work twice but I have no idea why they are working. They both happen to be within a function inside another function (plus the default new()) function and within the else step of an if then else statement. I recreated that layout with no such luck.

I've also confirmed that the application doesn't crash or pause but the display group disappears (or possibly is moved behind something else?).

Unrelated Question: Is it possible to pass a variable from one scene to the next?

Edit 2: I've narrowed the error down to the moveOn* animation types. It does not seem to occur on any of the other animation types. Hope this helps.
uid: 3325 topic_id: 2447 reply_id: 7758


[TOPIC: post.html]
#28

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

awesomeware14

Check this out:

local timerid = timer.performWithDelay(
   500, listener, 100 )
local timerid2 = timer.performWithDelay(
   1000, listener, 100 )        
 
-- Some point later in the app
function stopAllTimers()
        timer.cancel(timerid)
        timer.cancel(timerid2)
}

I got that in the Timer API: http://developer.anscamobile.com/content/timer-library

So, you could make a function like this:

local function changeScene ( scene, effect )
      timer.cancel(timerid)
      timer.cancel(timerid2)
      ...
      timer.cancel(timeridN)
      director.changeScene( scene, effect )
end
uid: 8556 topic_id: 2447 reply_id: 7863


[TOPIC: post.html]
#29

awesomeware14

[GLOBAL: userInfoPane.html]
awesomeware14
  • Observer

  • 10 posts
  • Guests

That does help with deleting timers but it doesn't help with the screen disappearing. Maybe I should explain the problem differently. I load the document 'play.lua' from 'main.lua' using the director class, then I draw my display objects and insert those objects into the group. I then load the functions (not call them) and then create a timer.performWithDelay to call the first function after a few seconds. Regardless of the delay time the display group disappears. However this is only true when using the moveFrom*. All of the other transition animations do not have this problem.
uid: 3325 topic_id: 2447 reply_id: 7873


[TOPIC: post.html]
#30

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

Can you send me the code or some code with the same problem?
uid: 8556 topic_id: 2447 reply_id: 7874


[TOPIC: post.html]
#31

awesomeware14

[GLOBAL: userInfoPane.html]
awesomeware14
  • Observer

  • 10 posts
  • Guests

Sure I'll throw together an example for you as soon as I get a chance. Also I would like to say other than this minor bug you did a great job this makes coding a lot easier!
uid: 3325 topic_id: 2447 reply_id: 7888


[TOPIC: post.html]
#32

mhennemeyer

[GLOBAL: userInfoPane.html]
mhennemeyer
  • Observer

  • 4 posts
  • Corona SDK

I have the same timer.performWithDelay => Black Screen problem.
Any luck yet?

Best
Matthias
uid: 6509 topic_id: 2447 reply_id: 8868


[TOPIC: post.html]
#33

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

That's very strange.. send me some code! I can't reproduce it
uid: 8556 topic_id: 2447 reply_id: 8880


[TOPIC: post.html]
#34

mhennemeyer

[GLOBAL: userInfoPane.html]
mhennemeyer
  • Observer

  • 4 posts
  • Corona SDK

It's just a plain call to timer.performWithDelay:
-- Inside scene.lua#new()#startGame()timer.performWithDelay(700, function(event)      if arrow then        localGroup:remove(arrow)        arrow = nil      end      createBall(xPos, yPos, xVel, yVel)      isPlaying = true    end)


when i load the scene from the game menu with "overFromRight",
everything works as expected; with "moveFromRight" i get the
mentioned black screen.

Matthias

BTW: Awesome work! Thanks!
uid: 6509 topic_id: 2447 reply_id: 8883


[TOPIC: post.html]
#35

mediakitchen

[GLOBAL: userInfoPane.html]
mediakitchen
  • Contributor

  • 433 posts
  • Corona SDK

Going to give this Director class a whirl and have a question.

I am placing all my game code into a file called screen2.lua

I can see that all display objects need to be inserted into localGroup - is that correct?

If so then what do I need to do with existing groups that contain images?

Foe example i have a group declared as follows:

local allBallsGroup = display.newGroup()

Do I need to do something like the following?

localGroup:insert( allBallsGroup )

Or am I getting a bit mixed up here?

uid: 7863 topic_id: 2447 reply_id: 9078


[TOPIC: post.html]
#36

mediakitchen

[GLOBAL: userInfoPane.html]
mediakitchen
  • Contributor

  • 433 posts
  • Corona SDK

Ignore my last post - sorted now! It was simply a case of inserting into the localGroup.

I am however experiencing an issue where sometimes when I load screen2.lua it displays a black screen when using move from right or move from left. Not a show stopper as works with the other transitions and as yet I have no preference as to which transition to use.

Great class! Thank you for sharing it.
uid: 7863 topic_id: 2447 reply_id: 9113


[TOPIC: post.html]
#37

mediakitchen

[GLOBAL: userInfoPane.html]
mediakitchen
  • Contributor

  • 433 posts
  • Corona SDK

Do you have a list of all things that need to be "cleaned" when switching between scenes?

I have realised certain things like transitions continue when I change scenes. Fortunately I have discovered there is a transition.cancel function that I can use to cancel these.

Would be useful to have a reference to other stuff that needs to be taken care of. For example, what would happen if the game was in the middle of a "for" loop moving objects and a user clicked a button to change scene?. I ask as I am getting a load of runtime errors when doing this and trying to track down the culprit.

uid: 7863 topic_id: 2447 reply_id: 9475


[TOPIC: post.html]
#38

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

mediakitchen, so sorry for the delay, I'm working on a game entirely with corona!

Director class can't remove timers, transitions and eventListeners. When you want to change scenes, put some function that remove all that things. As I said inthe director code page, I will work on that for the next versions!

Thanks for using director!
uid: 8556 topic_id: 2447 reply_id: 9513


[TOPIC: post.html]
#39

mediakitchen

[GLOBAL: userInfoPane.html]
mediakitchen
  • Contributor

  • 433 posts
  • Corona SDK

Hey no apology necessary!

Thank you for the reply to my question - that is fine to remove these elements manually. I guess I just assumed it did this automatically as it was so smooth an operation using the class for my game.

Thank you so much for sharing this with everyone.

Paul
uid: 7863 topic_id: 2447 reply_id: 9658


[TOPIC: post.html]
#40

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

Hey guys, this is important!

Talking to jmartinho by e-mail, he asked me about a custom clean() function that executes every time that scenes are changed. Director should execute this function, so he doesn't need to put the call in every file. So, I made a research and if you want the same functionality, just go to the end of the changeScene function and add the commented part below:

	-----------------------------------
	-- Clean up memory
	-----------------------------------
	
	if lastScene then

		-- If you want to use a custom function to clean, use this
--		if string.lower(lastScene) ~= "main" then
--			package.loaded[lastScene].clean()
--		end

		package.loaded[lastScene] = nil
	end
	lastScene = nextScene
	collectgarbage("collect")

As you can see, just before Director release the loaded file, you can make a call to any function of it. You can also use this type of call to other things but remember, you must create the same function name in EVERY file that Director will use as a scene!

Any doubts just tell me!
uid: 8556 topic_id: 2447 reply_id: 10722


[TOPIC: post.html]
#41

Magenda

[GLOBAL: userInfoPane.html]
Magenda
  • Contributor

  • 427 posts
  • Corona SDK

@ricardo

Just note that fxEnded ends *after* changeScene().
This can bring many complications if passed unnoticed.

Thanks again for sharing!
uid: 7356 topic_id: 2447 reply_id: 10729


[TOPIC: post.html]
#42

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

Magenda

You are right! All that clean up commands should be at fxEnded. I'll change it and post again soon. Thanks!
uid: 8556 topic_id: 2447 reply_id: 10756


[TOPIC: post.html]
#43

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

Hey ricardorauber,

you are my hero!

Thanks a million for this. :-)
uid: 9371 topic_id: 2447 reply_id: 11513


[TOPIC: post.html]
#44

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

Thanks dweezil!

I putted some important content in the http://developer.anscamobile.com/code/director-class-10
uid: 8556 topic_id: 2447 reply_id: 11524


[TOPIC: post.html]
#45

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

What should I do about freeing listeners created in each screen?
uid: 9371 topic_id: 2447 reply_id: 11535


[TOPIC: post.html]
#46

ricardorauber

[GLOBAL: userInfoPane.html]
ricardorauber
  • Contributor

  • 219 posts
  • Corona SDK

dweezil

You can create a function that removes all the listeners and when you call the changeScene, call this clean function first.

Future releases may control it for you, stay tuned.
uid: 8556 topic_id: 2447 reply_id: 11563


[TOPIC: post.html]
#47

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

SO I now have...

local function bt01t ( event )
if event.phase == "ended" then
cleanUP()
director:changeScene("screen1","moveFromBottom")
end
end

and...

local function cleanUP()
bt01:removeEventListener("touch",bt01t)
soccerball:removeEventListener("touch", movesoccerball)
soccerball1:removeEventListener("touch", movesoccerball1)
soccerball:removeEventListener("collision", soccerball)
soccerball1:removeEventListener("collision", soccerball1)
end

But now the event for the bt01 button is not fired. Why?
uid: 9371 topic_id: 2447 reply_id: 11599


[TOPIC: post.html]
#48

Magenda

[GLOBAL: userInfoPane.html]
Magenda
  • Contributor

  • 427 posts
  • Corona SDK

Have your clean() function be a global one and only call it from within director inside fxEnded.
uid: 7356 topic_id: 2447 reply_id: 11602


[TOPIC: post.html]
#49

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

But how will I then know which listeners to clear?
uid: 9371 topic_id: 2447 reply_id: 11606


[TOPIC: post.html]
#50

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

Just trying to understand the logic/flow of the director class.

So each time a new screen is transitioned to all the variables and objects of that screen are getting created each time?

If so then the clean routine has to remove all objects and nullify the local variables>?
uid: 9371 topic_id: 2447 reply_id: 11752



[topic_controls]
Page 2 of 4 1 2 3 4
 
[/topic_controls]