Book question: Intro > Book > Outro

I am using the example book code which starts with an intro scene however I want to change to an outro scene once the user gets to the last page of the book. What is the best way to do that?

Is there some documentation on the methods available in the director class somewhere without having to dig through the code? [import]uid: 91921 topic_id: 21673 reply_id: 321673[/import]

Have you tried taking a look at the Storyboard API? There is an eBook template if you choose New Project > eBook upon launching Corona. An ‘outro scene’ could just be another scene that automatically goes back to the beginning once some kind of sequence is finished. [import]uid: 52430 topic_id: 21673 reply_id: 85985[/import]

I hadn’t but it looks to be similar to the director class that I am using. Would prefer to stick with that and this was posted to the Director Class forum so was more looking for answers relating to that [import]uid: 91921 topic_id: 21673 reply_id: 85993[/import]

Dr Stripes, Where did you get the example book code from? [import]uid: 29300 topic_id: 21673 reply_id: 93807[/import]

I would also like to know. I appended a ending via the pagelist variable, but there is noway i can find to get back to the scene menu. If you call the change scene function, the app basically crashes. I am also not too sure about memory usage with the book part, seems it never destroys the display groups.

@dyanikian download director class 1.4, in the zip is a book template/example… [import]uid: 75514 topic_id: 21673 reply_id: 96985[/import]

Here is the working code, put it in pages.lua

  
//button image  
  
local button\_home = display.newImageRect("res/images/button\_home.png", 53, 53);  
 button\_home:setReferencePoint(display.CenterReferencePoint);  
 button\_home.x = 50; button\_home.y = 30;  
 button\_home.scene = "menu";  
 localGroup:insert(button\_home);  
  
//listener function  
 function changeScene(e)  
 if(e.phase == "ended") then  
 director:turnToScenes()  
  
 --director:changeScene("menu", "crossfade" ); -- Back to Menu  
 director:changeScene(e.target.scene, "crossfade" ); -- Button\_Defined Scene  
 -- Just uncomment which one you want to use  
 end   
 end  
  
//bind the listener to button  
button\_home:addEventListener("touch", changeScene);  
  

This obviously uses a button, but you can write the part to check if last page and if so, just call changeScene as such…

 function changeScene()  
 director:changeScene("outro", "crossfade" ); -- Send to outro.lua  
 end  
  
-- You code here checking page\_num and last\_ page data from director.lua  
  
if(var \>= num\_pages) then  
 changeScene();  
end  

Hope this helps! [import]uid: 75514 topic_id: 21673 reply_id: 96995[/import]

Jmarchalonis

Is it possible to to have pages respond to two different types of input:

Swipe left or right to move to next page (this already happens)
Tap a page to move to a new scene

I.ve tried adding a listener to the “image” on pages.lua but it doesn’t seem to work?
[import]uid: 97524 topic_id: 21673 reply_id: 105474[/import]

@dax

Sure is possible. You need to just copy the function changescene and rename it (only needed if you want to change the effect). When you declare your image/object, add scene = “scene_name”; Then add the listener to the image. I would actually attempt to get the working code for you, but I am out of the country. I get back in around a week so, if this didn’t help, I’ll look into it for you. I just believe you are missing the scene name attached to the image/object. Once you add that, it shouldn’t have any issues.

Hope that helped,
Jason [import]uid: 75514 topic_id: 21673 reply_id: 105723[/import]

Thanks

I listen for a tap event instead.

Strangely I find I have to tap twice in order to invoke the turnToScenes(), changeScene() code.

To get around this, I find I need to insert a small delay of 200ms before issuing turnToScenes(),changeScene() ?

Otherwise, it doesn’t respond properly ?

[import]uid: 97524 topic_id: 21673 reply_id: 105738[/import]

@dax

I think I misunderstood what you were asking earlier. I believe the issue you are having is due to layered listeners. There is a good read about it located at the following link. http://monkeybin.no/blog/archives/2011/08/08/corona-sdk-avoid-touch-events-through-layered-screens/

Basically, it is calling the listeners twice; run corona with terminal if on Mac and see if there is any crashes or error a read out. I believe that if you follow the guide, put a block layer over everything except the left/right borders, you can have the main/middle setup to send to another scene. You can also put a small block under an icon and it will work; I do this to send an email of a recipe in a book I made.

I really wish I had my development system with me, I have done what you are trying to achieve but I just don’t have access to my code. I am sure this article is what I used way back when. Anyway, take a look at it and see if it helps. Again, I think the listener is firing twice and you might be having errors on the backers. [import]uid: 75514 topic_id: 21673 reply_id: 105741[/import]

Thanks. I looked over that link, but it doesn’t seem to solve anything?

If you can imagine the whole screen is an image, which I can swipe left and right, so the next image appears.

If I tap on the image using my listener, it tells me in the terminal window, a tap event occurred, but no turntoscenes() or changescene() happens. If I tap a 2nd time, that’s when it happens.

I tried opening the sample “Book” application that comes with Director1.4 and the same problem occurrs?

Can someone verify this ? SImply add a tap listener and see if it takes one or two taps to turntoscene() changescene()

[import]uid: 97524 topic_id: 21673 reply_id: 105791[/import]

I still think it has to do with the layered listeners. Aside from that I can’t honestly say what’s wrong. I understand what you described but I never encountered that issue. Try setting the touch or tap event to change on begin rather than release. Try to debug it; print the target scene name and add flags within the changescene code.

If you don’t find a solution for this, I will figuare it out and get back to you in a week when I get home. It’s very hard to find a solution without having the code or tools at hand. [import]uid: 75514 topic_id: 21673 reply_id: 105805[/import]

Solution

It appears Director1.4 doesn’t like tap events, specifically when using PAGES. So as a workaround, I removed the tap event listener and replaced it with a touch event listener.

I modified the touch event listener so it would check if the x position at the start of the event didn’t change ie. was it a tap or not?

eg.

 local function imageListener( event )   
  
 if event.phase == "ended" then  
  
 -- this is another way of checking for a TAP event  
 -- director1.4 doesn't handle the tap event well  
 -- so we compare x value at start of touch, to it at the end eg. a tap  
  
 if event.xStart == event.x then  
  
 -- change from pages to scenes mode   
 -- and change scene  
  
 director:turnToScenes();  
 director:changeScene("menu");   
  
 end  
  
 end  
  
 end   

Notes:
I simply compare the x position values, which is fine for my particular use. However to detect a proper tap, perhaps it’s prudent to check if both x and y positions had changed.

Hope this is of some help to someone.

Update:
This runs fine on the simulator 2011.704, but when I just tested it on my iPhone 3Gs, it’s not responding properly. I have to touch the screen half a dozen times before it responds and does the turnToScenes() code. Will look into this further. May be a loading issue as I’m loading 52 playing card images into pagelist.

Added some simple jitter correction when comparing xStart with x and this did the trick…

[code]
if (event.xStart >= event.x -10) and (event.xStart <= event.x+10) then

– change from pages to scenes mode
– and change scene

director:turnToScenes();
director:changeScene(“menu”);

end
[/code] [import]uid: 97524 topic_id: 21673 reply_id: 105866[/import]