Methods
Introduction
These functions provide convenient techniques such as UI display, moving or kicking users, and playing sound.
Methods can be divided into UI, User Control, Sound, Communication, and Common depending on their purpose.
UI
loadSpritesheet
Function to read a sprite sheet picture file and make it an object
showCenterLabel
Function to display text for 3 seconds at the designated location for all players
showCustomLabel
Function to display text for 3 seconds at the designated location for all players
You can decorate text by inserting span
tags in the text part.
showWidget
Function to load the HTML file as a widget at the align position specified for all players
showYoutubeWidget
Function to call the YouTube video corresponding to the link to the widget
User Control
spawnPlayer
Function to move players to the designated X and Y coordinates
kickPlayer
Function to kick players
forceDestroy
Function to shut down the mini-game app
clearChat
Function to delete all chat history
getPlayerByID
Function to return a player corresponding to an id
Sound
playSound
Function to play the sound file
playSoundLink
Function to play the sound URL
stopSound
Function to stop all the playing sound
changeAttackSound
Function to change the poke (Z key) sound effects
Communication
httpGet
Function to request for HTTP Get
httpPost
Function to request for HTTP Post
httpPostJson
Function to request for HTTP Post in JSON
Common
sendUpdated
Function to apply the updated app/player-related field values when changes are made
save
Function to apply the updated app/player storage values
📚 API Explanation and Example
🎨 UI Methods
UI at a Glance
loadSpritesheet
App.loadSpritesheet(fileName: string, frameWidth: integer, frameHeight: integer, anims: array, frameRate: integer): ScriptDynamicResource
This function reads a sprite sheet picture file and makes it an object.
To better understand ScriptDynamicResource, please refer to the Understanding Sprite Sheets page.
Parameters
fileName
String
Name of the file to be loaded
frameWidth frameHeight
Integer
The frame’s width and height pixel size
anims
Array
Array of frame image numbers to be set as animation
frameRate
Integer
Rate of data displayed per frame frameRate: 8 → displays 8 images per second
Example
Paintman - Apply a Blueman sprite image
showCenterLabel
App.showCenterLabel(text: string, color: uint = 0xFFFFFF, bgColor: uint = 0x000000, offset: int = 0, time: number = 3000)
This function displays text for 3 seconds at the designated location for all players.
Parameters
text
String
Text to display on the label
color
Unit
bgColor
Unit
Background color of the label where a message is displayed If left blank, it is set to black (0x000000).
offset
Integer
The larger the offset value, the closer the displayed position is toward the bottom of the screen. If left blank, it is set to 0.
time
number
Label display time (ms), default 3000 ms (3 seconds)
Example
ssDisplay a message label with the yellow background.
showCustomLabel
App.showCustomLabel(text: string, color: number = 0xFFFFFF, bgColor: number = 0x000000, offset: number = 0, width = 100, opacity = 0.6, time: number = 3000);
This function displays text for 1 second at the designated location for all players. You can decorate text by inserting span
tags in the text part.
Parameters
text
String
Text to display on the label (span tags allowed)
color
Unit
bgColor
Unit
Background color of the label where a message is displayed If left blank, it is set to black (0x000000).
offset
number
The larger the offset value, the closer the displayed position is toward the bottom of the screen. If left blank, it is set to 0.
width
number
Value to set the label‘s width to n%. (default value: 100)
opacity
number
Value to set the transparency of the label’s background (default value: 0.6, range: 0-1)
time
number
Label display time (ms), default 3000 ms (3 seconds)
Example
Format the label based on the HTML tags.
sayToAll
App.sayToAll(text: string, color: uint = 0xFFFFFF)
This function displays text in the chat window.
Parameters
text
String
Text to display in the chat window
color
Unit
Example
Display an entrance message in light blue.
showWidget
App.showWidget(fileName: string, align: string, width: integer, height: integer): ScriptWidget
This function loads the HTML file as a widget at the align position specified for all players.
Parameters
fileName
String
Name of the file to be loaded
align
String
Where to display the widget ’popup’, ‘sidebar’, ‘top’, ‘topleft’, ‘topright’, ‘middle’, ‘middleleft’, ‘middleright’, ‘bottom’, ‘bottomleft’, ‘bottomright’
width height
Integer
Width and height of the area to display the widget (px)
Example
Create a Hangul game widget.
showYoutubeWidget
App.showYoutubeWidget(link: string, align: string, width: integer, height: integer): ScriptWidget
This function calls the YouTube video corresponding to the link to the widget.
Parameters
link
String
YouTube video’s url
align
String
Where to display the widget ’popup’, ‘sidebar’, ‘top’, ‘topleft’, ‘topright’, ‘middle’, ‘middleleft’, ‘middleright’, ‘bottom’, ‘bottomleft’, ‘bottomright’
width height
Integer
Width and height of the area to display the widget (px)
Example
Display a YouTube widget.
🙍♂️User Control Methods
User Control at a Glance
spawnPlayer
App.spawnPlayer(playerID: string, tileX: integer, tileY: integer)
This function moves the player corresponding to playerID to tileX and tileY coordinates.
Parameters
playerID
String
The player’s ID value
tileX tileY
Integer
The X and Y coordinates to move the player
Example
Move an entering player to the designated coordinates.
kickPlayer
App.kickPlayer(playerID: string)
This function kicks the player corresponding to playerID.
Parameter
playerID
String
The player’s ID value
Example
Create a command for kicking.
⛔ The kicked user will not be able to access the Space for 24 hours. Please use this command carefully.
forceDestroy
App.forceDestroy();
This function shuts down the mini-game app.
Example
End the mini-game app by force.
clearChat
App.clearChat();
This function deletes all chat history.
Example
Press Q to delete the chat history.
getPlayerByID
App.getPlayerByID(playerID: string);
This function returns a player corresponding to the id.
Example
How to use App.getPlayerByID
🔉 Sound Methods
Sound at a Glance
playSound
App.playSound(fileName: string, loop: boolean = false)
This function plays the sound file to all players.
Parameters
fileName
String
Name of the file to be loaded
loop
boolean
true: play on repeat false: play once
Example
Apply entrance music when a player enters (file).
playSoundLink
App.playSoundLink(link: string, loop: boolean = false)
This function plays the sound corresponding to the link to all players.
When the link does not play even though it is correct:
You have probably violated the CORS policy. If you cannot follow the CORS policy, it is recommended to use playSound by uploading the music file instead of playSoundLink.
Parameters
link
String
Sound url
loop
boolean
true: play on repeat false: play once
Example
Apply the entrance music when a player enters (sound url).
stopSound
App.stopSound();
This function stops all playing sounds.
Parameter
None
Example
Create a function that stops sound upon pressing q.
changeAttackSound
App.changeAttackSound(fileName:string)
This function changes the poke (Z key) sound effects.
Parameter
fileName
String
Name of the sound file to use
Example
How to use changeAttackSound
📡 Communication Methods
Communication at a Glance
httpGet
App.httpGet(url: string, headers: object, function(res: string){})
This function calls for HTTP Get request.
Parameters
url
String
Address to send the request to
headers
Object
Request header
res
String
Response to the request
Example
Change the nickname of an entering player using Korean Nickname Generator API.
httpPost
App.httpPost(url: string, headers: object, body: object, function(res: string))
This function calls for HTTP Post request.
Parameters
url
String
Address to send the request to
headers
Object
Request header
body
Object
Request body (form data)
res
String
Response to the request
Example
Receive the header and data sent by the app as a response and display in the chat window.
As shown in the example, key and value should be written in the form of a string, and the requesting server should receive form data and be able to process it.
httpPostJson
App.httpPostJson(url: string, headers: object, body: object, function(res: string))
This function calls for HTTP Post request in JSON.
Parameters
url
String
Address to send the request to
headers
Object
Request header. If blank, enter { }.
body
Object
Request body (JSON data)
res
String
Response to the request
Example
Receive the data sent by the app as a response and display in the chat window.
💠 Common Methods
Common Methods at a Glance
sendUpdated
App.sendUpdated()
This function applies the updated app-related field values when changes are made.
Parameter
None
save
App.save()
This function applies the updated app storage values when changes are made.
Parameter
None
Last updated