• Docs
  • Install
  • Follow @cosplayengine
  • v.0.9.5
  • GitHub
  • Watch
  • Examples
  1. Home
  2. UI Toolkit

UI Toolkit

  • Introduction
  • Install
  • ASCII Games
  • Demos
  • Examples
  • Macarena
  • Pong
  • Snake
  • Bird
  • Developer Guide
  • Quick Game 🏃
  • Key Concepts
  • Game Structure
  • Scenes & Objects
  • Log & Debugging
  • Pixels & Colors
  • Images
  • Keyboard Input
  • Sprite Animation
  • Shaders
  • Particle Effects
  • Fonts
  • Canvas Drawing
  • Text Input
  • Camera Tracking
  • Tile Mapping
  • Audio
  • Video
  • UI Toolkit
  • Build & Run

UI Toolkit

Although CosPlay does not define an opinionated UI framework, several sprites and supporting classes are often used for constructing UI elements on the screen. These include:

ClassDescription
CPLayoutSprite This sprite allows to dynamically layout other sprites based on text layout specification. Layout specification defines how one sprite should be positioned in relation to some other sprite.
CPDynamicSprite Common super-class for all sprites that support dynamic positioning. This class is used by CPLayoutSprite sprite and is the base class for all built-in sprites that support dynamic positioning.
CPLabelSprite Simple dynamic sprite that can be used for textual labels.
CPSpacerSprite Simple dynamic sprite that has no rendering content and provides only its dimension. This sprite is often used in dynamic layout to provide dynamic spacing between UI elements.
CPTitlePanelSprite A dynamic sprite that provides rendering of the single-character border with optional title. Often used by dialogs, popup windows and other UI elements that require a visual border.
CPListBoxSprite A dynamic sprite that provides combobox-like single-element UI selector.
CPTextInputSprite A dynamic sprite that provides standard text input field UI element.
CPSystemFont A system 1-character height font that should be used for UI elements.
CPSingletonSprite A convenient sprite that allows to execute a given function only once per given lifecycle scope, i.e. the scope of the scene object, the scene itself or the entire game.

Examples

The most effective way to see how these and other sprites can be used to create UI elements is to run and review the following examples that are pre-packaged with CosPlay:

ExampleRun & Code
Fonts

CPFontsExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.fonts.CPFontsExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:fonts
                            
Text Input

CPTextInputExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.textinput.CPTextInputExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:textinput
                            
Sprite Layout

CPLayoutExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.layout.CPLayoutExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:layout
                            
Dialog Support

CPDialogExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.dialog.CPDialogExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:dialog
                            
ListBox

CPListBoxExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.listbox.CPListBoxExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:listbox
                            

SBT & Maven

CosPlay comes with support for both SBT and Maven builds. Running examples and built-in games via SBT will automatically use terminal emulator since both SBT and CosPlay use JLine library and SBT therefor uses Java process fork to launch the examples and games. If you want to run directly in the terminal console using pure text-mode - use Maven method instead.

  • On This Page
  • Video
  • Create Clip
  • Play Clip
  • Useful Links
  • Example
  • Video Example
  • Quick Links
  • Discord
  • Stack Overflow
  • GitHub
  • @cosplayengine
  • YouTube
  • API
Copyright © 2023 Rowan Games, Inc. Privacy • Docs release: 0.9.5 Latest: