Hi,
I’m working on my first V-play game.
I’m using the Multi Scene Multi Level Game Template.
In one of my levels I have this code:
import QtQuick 1.1
import VPlay 1.0
Item {
property string levelName: "Thirty Consonants"
property url jsonFile: "../json/ThirtyConsonants.json"
Component.onCompleted: {
console.debug(jsonFile)
console.debug("inside ThirtyConsonants")
var data = fileUtils.readFile(jsonFile)
console.debug(data)
var jsonObj = JSON.parse(data)
console.debug("jsonObj")
console.debug(jsonObj)
function methodToCall(){
console.debug("methodToCall")
}
for(var i = 0; i < jsonObj.length; i++)
{
//print to console each of the consonants of the tibetan language
console.debug(jsonObj[i])
//THIS IS WHERE I WANT TO CREATE BUTTONS FOR EACH CONSONANT DYNAMICALLY
//SO THAT WHEN THE BUTTON IS TAPPED, IT PLAYS THE FILE ASSOCIATED WITH THAT CONSONANT
//e.g. a button that displays ཀ should play ཀ.wav
}
}
}
I need the code to put inside the for loop that will dynamically create the number of buttons depending on the length of the json.
After my research I found this:
var newEntityProperties = {
x: Math.random()*scene.width,
y: Math.random()*scene.height,
rotation: Math.random()*360
}
entityManager.createEntityFromComponentWithProperties(
boxEntity,
newEntityProperties);
My question is, how do I transform the above code to a button-like entity that will work inside for loop to create buttons dynamically????
Thank you very much.