Game Development Reference
In-Depth Information
// Check for the presence of an attribute
if (myInput.getAttribute("data-is-high-score")
== null) {
// If attribute is not present, add it to the
element with somedefault value
myInput.setAttribute("data-is-high-score",
false);
}
// If attribute is present, check its value
else {
var isHighScore =
myInput.getAttribute("data-is-high-score");
if (isHighScore) {
// Do something with this new high score
} else {
// The current score is not yet a new high
score
}
}
Used in the game
There were a couple of usages of custom data attributes in the game with dif-
ferent purposes and for different reasons. As mentioned previously, one use was to
specify a player's current speed. Two other instances of the attribute were used to
identify and distinguish a player from the other and to group separate buttons that
were intended to behave the same way.
Search WWH ::




Custom Search