Collection transitioning fade with sprite help

I’m trying to create a fade to black effect when switching between collections. My current method is a solid black sprite overlaying the view area. The z order is set to the back. I change the tint alpha to 0 and bring it forward when I need it then use animation to turn the collection view black. This seems to work well for closing a collection, however, it does not work well for starting a collection.

When I load the game proxy collection, I pull the Black sprite to the front and animate the tint alpha to 0. This works but there is a split second when the full collection is viewable before the black sprite is moved forward on the z. How can I fix this other then set the black sprite in the front in the collection editor? (This makes it harder to edit the collection)

Thanks

Hmm, when do you move the black sprite to the front? I assume you’re doing it using go.set_position()? Is the black sprite in the loaded collection? You can probably wait for proxy_loaded, then do init and at the same time move the black sprite to front and then do enable?

By the way, have you considered using a full screen gui node instead to cover both gui and game objects (or maybe you have modified the default render script to take care of this)? And have you seen this post about transitions using stencil buffers?

Yes, to clarify: “init” calls the init() function on any script component. “enable” starts displaying sprite conponents etc and the calling of update() each frame.

Thanks guys, I’ve tried moving the sprite before the enable call but I still seem to get the split second without the overlay sprite. I’m very new to Defold so I’m probably doing something wrong.

@britzl I did see that thread but I can’t quite grasp the concept yet so figured I’d try a method i’ve used before.

Can I enable a collection proxy from inside a scripts init() that is located inside the collection?

No, the proxy must receive the init message first for the init()s inside the collection to be called, so it has to happen from outside.

I tried moving the sprite from outside the collection but get this error: “function called can only access instances within the same collection.”

Yes, you need to message pass into the collection.

Sorry guys, I’m still stumped. for simplicity sake, lets forget about the fade effect. I just want to move a sprite thats at a -1 z to the front before the collection is rendered.

  1. I call load on my collection proxy
  2. In the return proxy_loaded message I call init on the collection.
    • A script on my go in the collection uses go.set_position inside the init moving the z to 1.
  3. I call enable on the collection to start rendering
  4. The collection displays and seems to take 1 frame to move the go sprite to the front. thus causing a flicker effect.

Those steps all seem correct. I’m really surprised that it doesn’t work. I’m traveling all day, but once I get to a hotel I’ll give this a try as well.

BTW, You could also experiment with sending enable/disable to the sprite component to show/hide it.