Skip to main content

Intents

Intents describe what should happen when a button is clicked. This page will cover the most common use cases for intents.

PressIntent

Use a Button with a PressIntent to trigger a signal when a button is pressed. Then listen for Pressed signals to respond to the button being pressed.

Most commonly, you would use a RaisedButton with backgroundColor=Color:Primary to create a button that stands out and looks clickable, like this:

pub game fn World.Main() {
SpawnEachPlayer owner {
Content {
RaisedButton(PressIntent<attack>, backgroundColor=Color:Primary) { "Attack" }
}

on Pressed<attack> that {
Print { "And now we attack!" }
}
}
}

See also HoldIntent, which triggers not just when the button pressed, but also when it is released.

Keycodes as Intents

Let's say you have a spellcasting game, where players press buttons to cast spells. To cast a fireball, they can either press the spacebar on their keyboard, or click the user interface button that says "Fireball".

A good way to do this is to create a Button that uses a Keycode as an Intent. That way, whether the player clicks the button or presses the spacebar, it will trigger the same signal which you can handle the same way:

pub game fn World.Main() {
SpawnEachPlayer owner {
Content {
RaisedButton(KeySpacebar, backgroundColor=Color:Primary) { "Fireball" }
}

on ButtonDown(KeySpacebar) {
Print { "Taste my fireball! Rawrrrr!" }
}
}
}

Page and Game Intents

A button can take you to a different page when clicked by giving it the page fn as its intent. Give a button a game fn as its intent to enter that game when the button is clicked.

pub page fn owner.HomePage {
Content {
RaisedButton(Main, backgroundColor=Color:Primary) { "Play" }
RaisedButton(AboutPage, backgroundColor=Color:Secondary) { "About" }
}
}

pub page fn owner.AboutPage {
Content {
P { "This is a game about ducks and bread" }
}
}

pub game fn World.Main() {
Content {
P { "Welcome to the game!" }
}
}

See Entrypoints to learn more about pages and games.

Linking using Intents

You may want to create links to other pages, for example a link to your game's Discord server. You can do this by:

  • Use a Link style of Button to create a link that looks like a hyperlink.
  • Simply use the String URL as the intent to make it open the URL when clicked. Make sure your URL starts with http:// or https://.
pub game fn World.Main() {
Print {
Link("https://easel.games") { "Link to My Favorite Website" }
}
}

Show on Hover Intents

The ShowOnHoverIntent allows you to display helpful information when the player is hovering over a button. This is useful when the simple text tooltip parameter of a Button is not enough, and you want to show a more complex UI when the player hovers over a button. For example, this could be used to display the stats of a weapon when the player hovers over that weapon's button in the inventory.

pub game fn World.Main() {
SpawnEachPlayer owner {
Content {
RaisedButton([PressIntent<attack>, ShowOnHoverIntent<attack>], backgroundColor=Color:Primary) { "Attack" }
}
BottomRightContent<attack>(dismissed=true) {
ShinyPanel(backgroundColor=#b0f, maxWidth=30) {
H1 { "Attack" }
P {
"Swing your mighty sword for 10 damage! "
"This attack is super effective against goblins, but not very effective against armored knights."
}
}
}

on Pressed<attack> that {
Print { "And now we attack!" }
}
}
}
tip

ShowOnHoverIntent has zero lag because it is processed entirely on the client. If you were to code this yourself using HoverIntent, there may be a delay between when the player starts hovering and when the hover UI appears, because the hover signal has to be sent across the network before it can be processed. This is why you may want to use ShowOnHoverIntent where possible.