I have the following JavaScript that runs when my game board loads:
if (runtimeScene.getTimeManager().isFirstFrame()) {
// Iterate through all objects of type "Sprocket" on the "Sprockets" layer
const sprockets = runtimeScene.getObjects('Sprocket');
// Loop through each object and set a random rotation angle
for (let i = 0; i < sprockets.length; ++i) {
// Set a random rotation angle (0, 90, 180, or 270 degrees)
const randomRotation = Math.floor(Math.random() * 4) * 90;
sprockets[i].setAngle(randomRotation);
}
}
The purpose is to randomize the angles the sprockets appear on the board. I’d like to be able to call that function when the player taps a button called “BtnResetScenario”, so they can randomize the board again. Currently, the button just reloads the screen, which works, but I think it would be a more efficient to just have the button call the function.
Anybody know how to do that with a button “BtnResetScenario”?