I just released Hunter RPG tease which has few more features.I wanted to share what I made. Maybe you could use parts of my code for your own tease.
Audio playing library
I was able to use event listeners to make audio playable one after another within one page and then to go to another page without adding additional timers. When all samples are over, page is changed automatically, so you don;t have to worry about calculating time of sound and so on.
Code of library is here:
Code: Select all
var listOfSoundsWithListener = []
var listToPlayGlobal = []
function wait(ms){
var start = new Date().getTime();
var end1 = start;
while(end1 < start + ms) {
end1 = new Date().getTime();
}
}
function InList(array, toFind){
for(var i = 0; i < array.length; i++) {
if (array[i] == toFind) {
console.log(true)
return true
}
}
console.log(false)
return false
}
function playNext () {
wait(50)
listToPlayGlobal.shift()
console.log("list "+listToPlayGlobal)
if(listToPlayGlobal.length> 0){
console.log('playing now: '+listToPlayGlobal[0])
Sound.get(listToPlayGlobal[0]).play()
}
else{
pages.goto(goToNext)
}
}
function playList(){
listToPlayGlobal = list
console.log(listToPlayGlobal);
for(i = 0; i< listToPlayGlobal.length; i++)
{
if(!InList(listOfSoundsWithListener,listToPlayGlobal[i])) {
listOfSoundsWithListener.push(listToPlayGlobal[i])
Sound.get(listToPlayGlobal[i]).addEventListener('end',function(){
playNext()
}
)}
}
Sound.get(listToPlayGlobal[0]).play()
}
function StopPlaying(){
Sound.get(listToPlayGlobal[0]).stop()
}
Code: Select all
list = [
'sound1',
'sound2'
]
goToNext = "somePage"
playList()
Shop
This took me a while until I made it work properly. Here is what you need in init script:
Code: Select all
var city1ArmorSelected = -1
var city1ArmorAvailable = [1,2,3]
//get your exuiped armor
function GetArmor(){
return armorList[Get("armor")]
}
//set your equiped armor
function SetArmor(armorID){
Set("armor",armorID)
}
//get armor by ID from list
function GetArmorByID(id){
return armorList[id]
}
//cost,name,exp,speed,timeStrokes,metronome1-1,metronome2-3,metronome3-3,metronomeFast,edge,holdEdge,chanceToRelease,desc //12
var armorList = [
[0,"No armor",0,0,0,0,0,0,0,0,0,0,""],
[200,"armor name",5,1,0,0,0,0,0,0,0,0,"Some description"]
]
city1ArmorAvailable contains armors available in City1
city1ArmorSelected is a current value you see right now in a shop.
Shop itself is displaying everything you need based on list of items specified in city1ArmorAvailable list and then from armorList . I believe the easiest way to see how it was done, is to download tease and load it in your editor.
There are couple of other things added but it is too much to explain.
Please feel free to post questions or give feedback. You are also welcome to download, edit, change and release your own version of that tease