Is there an easy way to use spread pages?
I tried placing the same instance in leftpage.tscn and rightpage.tscn and shifting the rightpage, but I realized the synchronization eventually gets out of sync.
Send me the project and an explanation of what is happening to you exactly, because from your explanation I can’t see the problem.
If you mean that your scene plays a seamless animation that looks fine when you place the same scene on the left page and on the right page, that animation can “break” when turning pages because, during the animation, the script has to take the scene out of the current viewport (slot1 = left page, slot2 = right page) and move it into slot3 (the initial face of the animated page), in order to configure the other slots with the correct images.
That movement of nodes can break any seamless animation that was formed by two pages together.
If you mean something else, send me the project and I’ll take a look at it.
Video.
https://x.com/ponidog/status/1999760362678452638
Separate tscns are prepared for the left and right pages, with the target instance placed in both. The right page's coordinates are shifted by the page width.
・Initially, a single tscn was https://x.com/ponidog/status/1999760362678452638placed on both pages and shifted for the right page, but since the left page was also affected, it was split into separate left and right pages.
The problem is the one I mentioned before: because of how the viewports are updated and the fact that the scene is taken out of one side and inserted into another, animations like the one you show end up becoming desynchronized by a few frames. You have to control that manually in your scripts.
I’ve added two signals to the pageflip script. You can download the new file and play with those signals to “synchronize your scenes.” The signals are started_page_flip_animation and ended_page_flip_animation, and they are emitted when the page-flip animation is about to start and when it finishes.
To connect those signals to your scripts, you can use the BookAPI so your scenes can retrieve the active book when they enter the scene tree (var book: PageFlip = BookAPI.get_current_book()). From there, you can connect to the book’s signals to synchronize your scenes.
You can do this when the scenes enter the tree: get the book, check that you’re not already connected to it, and then connect it to your script. The logic to actually synchronize the pages is something you’ll need to implement yourself.
By the way, in the pageflip inspector, if you enable enable_composite_pages and assign a page texture (the blank sheet of paper) to blank_page_texture, textures/scenes with transparency will be drawn on top of the paper.
For the lag, you could connect the signals as deferred (.connect(_any_method, CONNECT_DEFERRED)) so the synchronization is pushed to the next frame, when the engine has some free time, instead of overloading a single frame with both page creation and synchronization.
Alternatively, you could use several awaits to wait a few frames before synchronizing. If it’s a heavy function, you could split it into multiple functions that do a small part each frame, or even use a secondary thread to run the synchronization.
All of these approaches could help reduce the initial micro-lag.