Enable the tap command only after a certain event
Good morning everyone will read my question.
I would like to know if it is possible to create a code that does what I have written, I am creating a lens in which there are various objects that appear on tap on the screen. Each event at the opening of the mouth perform an event in which an audio and a written part.
Now my problem arises, if during this event someone touches the screen, changes the highlighted object, the audio file and the text continue, but they are no longer reset.
I would just like to enable the tap only after the audio file and the text have disappeared so as not to create errors, I enclose my simple code, I'm new in this.
Thanks to anyone who answers me
// -----JS CODE-----
// @input Component.SpriteVisual billboardSprite
// @input Asset.AudioTrackAsset audioTrack
// @input float showTime = 4.0
var audioComponent = null;
function onMouthOpened( eventData )
{
script.billboardSprite.getMaterial(0).getPass(0).baseColor = new vec4(1, 1, 1, 0.5);
audioSetup();
if( script.billboardSprite )
{
script.billboardSprite.enabled = false;
}
// Show billboard
if( script.billboardSprite )
{
script.billboardSprite.enabled = true;
// Start the delay
delayedEvent.reset(script.showTime);
// Play animation
var control = script.billboardSprite.getMaterial(0).getPass(0).baseTex.control;
if( control && control.play )
{
control.play(1, 0.0);
}
}
// Play sound
if( audioComponent )
{
audioComponent.play( 1 );
}
}
var event = script.createEvent("MouthOpenedEvent");
event.faceindex = 0;
event.bind(onMouthOpened);
function onDelay( eventData )
{
script.billboardSprite.enabled = false;
}
var delayedEvent = script.createEvent("DelayedCallbackEvent");
delayedEvent.bind( onDelay );
function audioSetup()
{
if( script.audioTrack && !audioComponent )
{
audioComponent = script.getSceneObject().createComponent("Component.AudioComponent");
audioComponent.audioTrack = script.audioTrack;
}
}
Hey Cristian, just to clarify to make sure I'm understanding what you're looking for:
Is this correct?
Hi Travis, thank you for your time.
I have an event that activates when I open my mouth (a sound activates, lasts 4 seconds and a screen appears on the screen) and another one whose touching one side of the screen changes the object I see represented. When I open my mouth and then start the sound and the text I would like to block the ability to tap the screen and re-enable it when the event of sound and image end. Another thing, but I think that solving this also solves the other problem, when the last object appears on the screen, in addition to having sound and text activated when I open my mouth, also start a small animation, I would also block the tap until the audio is not finished, I hope I managed to explain
Another thing, I also attach the code for the tap
// -----JS CODE-----
//@input SceneObject[] items
// @input float showTime = 4.0
//Array are indexd from 0.
//Disable everythinh but the first (0th) item
for (var i = 1; i < script.items.lenght; i++)
{
script.items[1].enable = false;
}
//Activate the next item on TouchStartEvent.
// We remember what item is currently visible.
// When we start it’s the 0th item.
var currentItemIndex = 0;
// Define what happens when you tap.
function activateNextItem () {
// Disable the current item.
script.items[currentItemIndex].enabled = false;
// Increment the current item index
currentItemIndex += 1;
// We need the current item index to wrap around
// once it's higher than the number of items we have.
currentItemIndex = currentItemIndex % script.items.length;
// Enable the new item.
script.items[currentItemIndex].enabled = true;
}
//Bind the function to the touch event.
var touchEvent = script.createEvent("TapEvent");
touchEvent.bind(activateNextItem)
Hi Christian, this script I created should help steer you in the right direction.
It binds three events - open mouth, tap and a delayed event. When open mouth happens, there's a bool that disables the inside of the tap event. Then, it starts a delayed event with a configurable amount of time (make sure you tune in the inspector). When the delay event gets called, it re-enables the tap until the next open mouth.
https://pastebin.com/D1HMBr1h
Hi Travis, you're a god!
Thank you thank you!!!!
Hi,
can you help me with my Randomizer Script?
I have a lens with randomizer music (image_randomizer template) with TAP! event, for now if the user TAP the randomizer start but if TAP again the randomizer start again and I got double sound running at the same time,
I would like to do: The user can`t TAP again until the music stops
Script:
//@input Asset.Texture[] image {"label": "Images"}
//@input Asset.Texture defaultTex {"label": "Defaul Texture"}
//@input Component.Image bubble
//@input bool advanced = false
//@ui {"widget":"group_start", "label":"Advanced", "showIf": "advanced"}
//@input float delayBetweenImages = 0.1 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01}
//@input float delayBeforeStop = 1.5 {"widget":"slider", "min":0.0, "max":3.0, "step":0.01}
//@input SceneObject objectWithTweens
//@ui {"widget":"group_end"}
var bubblePass = script.bubble.mainMaterial.mainPass;
var n = script.image.length;
var image = script.image;
var curIndex = -1;
var tapTrigger = script.createEvent("TouchStartEvent");
tapTrigger.bind(randomizeStart);
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(updateFunc);
function randomizeStart() {
// Stop tweening the default image
global.tweenManager.stopTween(script.objectWithTweens, "ALPHA");
global.tweenManager.startTween(script.objectWithTweens, "ALPHA-100");
// start randomizing, disable user input
randomizeStartTime = getTime();
updateEvent.enabled = true;
tapTrigger.enabled = false;
}
function updateFunc() {
var curTime = getTime();
// If still choosing random image
if ((curTime - randomizeStartTime) < script.delayBeforeStop) {
if ((curTime - setImageTime) > script.delayBetweenImages) {
// Prevent selecting the same image twice
var index = randomInt(n);
var i = 0;
while (index == curIndex && i < 10) {
index = randomInt(n);
i++;
}
setImageTime = curTime;
// Set the displayed image to the selected texture
bubblePass.baseTex = image[index];
curIndex = index;
}
} else {
// Play a tween when we've chosen an image'
if ((curTime - randomizeStartTime) > script.delayBeforeStop - 0.4) {
global.tweenManager.startTween(script.objectWithTweens, "SCALE");
global.behaviorSystem.sendCustomTrigger ("play_" + curIndex);
}
// Enable user input once we've chosen an image'
updateEvent.enabled = false;
tapTrigger.enabled = true;
}
}
function randomInt(val) {
return Math.floor(Math.random() * Math.floor(val));
}
function init() {
setImageTime = 0;
randomizeStartTime = -1;
bubblePass.baseTex = script.defaultTex;
// Add some effect so the Lens feels dynamic before the user starts playing
global.tweenManager.startTween(script.objectWithTweens, "ALPHA");
updateEvent.enabled = false;
}
init()