Medals. Medal

Medal - Tracks an unlockable medal

Constructor

new Medal(id, name, descriptionopt, iconopt, srcopt)

Create a medal and add it to the list of medals

Parameters:
NameTypeAttributesDefaultDescription
idnumber

The unique identifier of the medal

namestring

Name of the medal

descriptionstring<optional>

Description of the medal

iconstring<optional>
🏆

Icon for the medal

srcstring<optional>

Image location for the medal

Example
// create a medal
const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');

// initialize medals
medalsInit('Example Game');

// unlock the medal
medal_example.unlock();

Members

description

Properties
TypeDescription
string

Description of the medal

icon

Properties
TypeDescription
string

Icon for the medal

id

Properties
TypeDescription
number

The unique identifier of the medal

image :HTMLImageElement|undefined

Type:
  • HTMLImageElement | undefined
Properties
TypeDescription
HTMLImageElement | undefined

Source image for the medal icon, if any

name

Properties
TypeDescription
string

Name of the medal

unlocked

Properties
TypeDescription
boolean

Is the medal unlocked?

Methods

isLocal() → {boolean}

Whether the local save holds this medal, it is neither loaded nor written while a service like Newgrounds holds it

Returns:
Type: 
boolean

render(hidePercentopt)

Render a medal

Parameters:
NameTypeAttributesDefaultDescription
hidePercentnumber<optional>
0

How much to slide the medal off screen

renderIcon(pos, size)

Render the icon for a medal

Parameters:
NameTypeDescription
posVector2

Screen space position

sizenumber

Screen space size

unlock() → {Promise.<boolean>}

Unlocks a medal if not already unlocked

  • The promise is optional, for when a game wants to know the outcome
Returns:
  • Whether the medal is unlocked, right away unless a service like Newgrounds has to confirm
Type: 
Promise.<boolean>