只是提醒一下,我终于想出了如何做我需要做的事情,它看起来像这样:
const TouchGestures = require('TouchGestures');
const Scene = require('Scene');
const D = require('Diagnostics');
//scene assets:
const asset1 = Scene.root.find('plane0');
const asset2 = Scene.root.find('plane1');
const asset3 = Scene.root.find('plane2');
//assets put into array:
const myArray = [asset1,asset2,asset3];
//initial visibility state for assets:
var hideStates = [0,1,1];
//set initial visibility:
hide(myArray,hideStates);
//MAIN EVENT___________________________________________________________________________________
TouchGestures.onTap().subscribe(function (gesture) { // cycle visibility for assets on event
var hideStates = [1,1,1];
hide(myArray,hideStates);
unHide(myArray);
});
//_____________________________________________________________________________________________
//this will move through an array one step at a time, returning the index...
var cycler = {
current: -1,
cycle: function(arr) {
if (this.current == arr.length -1) {
this.current = 0;
} else {
this.current++;
}
return this.current;
}
};
function hide(assets,states) {
for (var i = 0; i <assets.length; i++) {
assets[i].hidden = states[i];
}
};
function unHide(assets) {
var unhide = cycler.cycle(myArray);
myArray[unhide].hidden = 0;
};
不确定这是否是最好的做事方式,但它确实有效!