sprite behavior settings
Hi :)
So I'm having issues with my lens starting when I want it to. I have a few 2d animation sprites that I'm using and I would like them to play just once when the camera finds my tracker. I was able to figure out a way to get them to play only once then staying frozen using a behavior script but my issue now is that they don't seem to play every time I open the lens like it says in the behavior script. Is there a way to program my lens so that every time it finds the image I'm tracking it will play my animations? I'm assuming its because it literally plays the animation as soon as the lens is open regardless of whether or not it is on the screen but I'm unsure how to work around this. Any tips help!
Thank You!
Lewis
Hi Lewis Falconer
This might help using the marker template and using it as reference,
this is the script used for the marker controller:
// MarkerController.js
// Version: 0.0.2
// Event: Lens Initialized
// Description: Controls the marker found and lost behavior.
// @input bool advanced = false
// @input Component.MarkerTrackingComponent marker {"showIf": "advanced"}
// @input Component.ScriptComponent crossHintScript {"showIf": "advanced"}
// @input Component.ScriptComponent fadeEffectScript {"showIf": "advanced"}
// @input Component.ScriptComponent hintControllerScript {"showIf": "advanced"}
function onLensTurnOnEvent()
{
if(script.fadeEffectScript)
{
if(script.fadeEffectScript.api.resetFadeEffect)
{
script.fadeEffectScript.api.resetFadeEffect();
}
}
}
var turnOnEvent = script.createEvent("TurnOnEvent");
turnOnEvent.bind(onLensTurnOnEvent);
script.marker.onMarkerFound = wrapFunction(script.marker.onMarkerFound, function()
{
if(script.hintControllerScript)
{
if(script.hintControllerScript.api.hide)
{
script.hintControllerScript.api.hide();
}
}
else
{
print("MarkerController: Please assign hint controller");
}
if(script.crossHintScript)
{
if( script.crossHintScript.api.startCrossAnimation)
{
script.crossHintScript.api.startCrossAnimation();
}
}
else
{
print("MarkerController: Please assign cross hint");
}
var markerObject = script.marker.getSceneObject();
if(markerObject)
{
for( var i = 0; i < markerObject.getChildrenCount(); i++ )
{
var childObject = markerObject.getChild( i );
for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
{
var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
if(objectsScript.api)
{
if(objectsScript.api.onMarkerFound)
{
objectsScript.api.onMarkerFound();
}
}
}
}
}
if(script.fadeEffectScript)
{
if(script.fadeEffectScript.api.startFade)
{
script.fadeEffectScript.api.startFade();
}
}
});
script.marker.onMarkerLost = wrapFunction(script.marker.onMarkerLost, function()
{
if(script.hintControllerScript)
{
if(script.hintControllerScript.api.show)
{
script.hintControllerScript.api.show();
}
}
else
{
print("MarkerController: Please assign hint controller");
}
var markerObject = script.marker.getSceneObject();
if(markerObject)
{
for( var i = 0; i < markerObject.getChildrenCount(); i++ )
{
var childObject = markerObject.getChild( i );
for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
{
var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
if(objectsScript.api)
{
if(objectsScript.api.onMarkerLost)
{
objectsScript.api.onMarkerLost();
}
}
}
}
}
if(script.fadeEffectScript)
{
if(script.fadeEffectScript.api.resetFadeEffect)
{
script.fadeEffectScript.api.resetFadeEffect();
}
}
});
function wrapFunction(origFunc, newFunc)
{
if (!origFunc)
{
return newFunc;
}
return function()
{
origFunc();
newFunc();
};
}
Hey,
Thank you for replying! I'm a little confused, is this the same script as what comes with the app? Or has this been modified? I see that the script in mine is version 0.0.1 where as yours is 0.0.2. I don't have any experience coding Java Script so I'm a bit unsure of where to start looking
Thanks!
I believe it has been modified, I recommend using the marker template from lens studio,
and editing the edit tabs and disable the assets not required.