Implementing a Processing app inside another one

It is complicated because you assumed there is a simple answer :grin: when in fact there just isn’t one.

Processing was designed to support just one display window per sketch and that sketch has its own event handling and rendering threads. Trying to run a second sketch inside an existing one will result in thread conflict and concurrent access issues.

In your scenario (“Space Casino”) where you have multiple mini-games to switch between e.g. “Wheel of Fortune”, “Slot Machine” and “Mind Games” I can see two possible solutions.

  1. Multiple Windows. You have the main casino window with the game selection buttons and when you click on one the selected mini-game starts in a new window. Both G4P and controlP5 support multiple windows and if you didn’t want to use a library there are window creation examples to be found on the forum.

  2. Single Window. The sketch effective has a number of modes and each mode represents a mini-game. This discussion might give you some ideas how it might be implemented.

4 Likes