The JS API for the SuperFive.io gaming platform where players can compete in a hypercasual games tournament
npm install com.superfive.jsThis is the JS API for the SuperFive.io gaming platform where players can compete in a hypercasual games tournament. Use it to adapt your game for the platform.
In general adpating your game isn't gonna be much work. You only have to listen to a few events, consider some states and send a `game_ready.
`js
import {
isInPlatformMode,
subscribeToPlatformMessages,
sendReady,
sendWin,
sendLose,
} from 'com.superfive.js'
// Check if the platform is loading this game
if (isInPlatformMode()) {
// Subscribe to the platform's messages
subscribeToPlatformMessages();
window.addEventListener('platformMessage', (event: Event) => {
const customEvent = event as CustomEvent;
const { type } = customEvent.detail;
if (type === 'game_restart') {
yourStartGame();
}
});
create() {
// As soon as the game is loaded and ready to play send the 'ready event'
sendReady();
}
yourStartGame() {
// The user on the plafrom clicked "Start Game" ...
// Your game should run now / play sound effects etc
}
onWin() {
// If the player wins, pause the game, mute all sounds and let the platform know:
sendWin();
}
onLose() {
// If the player loses, pause the game, mute all sounds and let the platform know:
sendLose();
}
}
`
The platform can send the following events to your game:
This event is dispatched when the platform sends a message to your game. Listen for this event to handle platform communications.
Event Structure:
`js`
{
detail: {
type: string, // The message type
payload: any // Optional payload data
}
}
Available Message Types:
- game_restart - Platform requests the game to (re)startgame_mute
- - Platform requests the game to mute/unmute audio
Example:
`js`
window.addEventListener('platformMessage', (event) => {
const customEvent = event as CustomEvent;
const { type, payload } = customEvent.detail;
switch (type) {
case 'game_restart':
// Restart your game
break;
case 'game_mute':
// Handle mute/unmute based on payload
const isMuted = payload.muted;
break;
}
});
#### isInPlatformMode(): boolean
Checks if the game is running within the SuperFive platform.
Returns: boolean - true if running in platform mode, false otherwise
Example:
`js`
if (isInPlatformMode()) {
// Game is running in SuperFive platform
console.log('Platform mode detected');
}
#### getDifficulty(): number
Gets the difficulty level set by the platform.
Returns: number - Difficulty level (0-2)0
- - Easy (default)1
- - Medium 2
- - Hard
Example:
`jsGame difficulty: ${difficulty}
const difficulty = getDifficulty();
console.log();`
#### startMuted(): boolean
The player can set if they want to play without sound effects.
This should be checked before starting the game or playing any sounds.
Returns: boolean
Example:
`jsGame muted?: ${isMuted}
const isMuted = startMuted();
console.log();`
#### subscribeToPlatformMessages(): void
Subscribes to platform messages. Call this when your game starts to receive platform events.
Example:
`js`
// Subscribe to platform messages
subscribeToPlatformMessages();
#### unsubscribeFromPlatformMessages(): void
Unsubscribes from platform messages. Call this when your game is shutting down.
Example:
`js`
// Clean up when game ends
unsubscribeFromPlatformMessages();
#### sendPlatformMessage(type, payload?): void
Sends a message to the SuperFive platform.
Parameters:
- type - Message type (see PlatformMessage types below)payload
- - Optional data to send with the message
Example:
`js`
// Send custom message with data
sendPlatformMessage('custom_event', { score: 100 });
#### sendReady(): void
Notifies the platform that your game is loaded and ready to play.
Example:
`js`
// When your game is fully loaded
sendReady();
#### sendWin(): void
Notifies the platform that the player has won the game.
Example:
`js`
// When player completes the game successfully
sendWin();
#### sendLose(): void
Notifies the platform that the player has lost the game.
Example:
`js`
// When player fails the game
sendLose();
The following message types can be sent to the platform:
`typescript`
type PlatformMessageType =
| 'game_ready' // Game is loaded and ready
| 'game_won' // Player won the game
| 'game_lost' // Player lost the game
| 'game_restart' // Platform requests restart
| 'game_mute' // Platform requests mute/unmute
If your game is already hosted somewhere, send us the link (dev@superfive.io).
As we strive for quality we can not accept any game.
- The game should work in portrait (9:16)
- The game should work on desktop (mouse input) and mobile (touch input)
- The game should not start unless it receives the game_restart` message from the platform
- The game should not play any music - only sound effects (the platform plays music)
- Make sure your game loads fast. We are trying to cater to people globally and everyone should be able to play.
- The game can have different difficulty levels (0 = 'Easy', 1 = 'Medium', 2 = 'Hard').
As for now we do not have any games store or games simulator to test the game integration.
Send us a static build of your game and we host it on our cloud.
Contact dev@superfive.io