To catch the "Ad finished" event in the Crazy Games SDK, you can use the following code:
// Add a listener for the "Ad finished" event
crazySdk.addEventListener('adFinished', function() {
// Go to the next layout
System.gotoLayout('nextLayout');
});
// Display the ad
crazySdk.displayAd('midgame');
// Wait for the ad to finish
await crazysdk.waitForAdToFinish();
The waitForAdToFinish() method will block until the ad has finished playing. This ensures that the player is not taken to the next layout before the ad has finished playing.
Here is a modified version of your event that uses the above code to catch the "Ad finished" event:
// Display the ad on a specific layout
System.setLayout('adLayout');
crazySdk.displayAd('midgame');
// Wait for the ad to finish
await crazysdk.waitForAdToFinish();
// Go to the next layout
System.gotoLayout('menuCards');
This event will display the ad on the adLayout layout and then wait for the ad to finish playing before going to the menuCards layout.
I hope this helps!