How to toggle between pointer up and pointer down

I would like to toggle between pointer up and pointer down.
I would like to toggle and turn of and on a photo sphere image. Currently I need to touch and hold the plane to trigger the pointerdown but as soon as I stop touching it. It goes back to pointer up. I would like to toggle between both a click at a time and not have to hold it.
Thanks,

This is the code I have below.

var background1 = parent;
var PhotoSphere = symbol.nodes.PhotoSphere;

parent.on(“pointerdown”, parent_pointerdown);
parent.on(“pointerup”, parent_pointerup);
// Runs when pointerdown occurs on the parent node
// The argument e contains useful info about this event:
// https://docs.zap.works/studio/scripting/reference/object/events/pointerdown/

function parent_pointerdown(){
    
   PhotoSphere.visible(true);

}
function parent_pointerup(){

   PhotoSphere.visible(false);

}

Hi There,

If you would prefer a toggle as opposed to a “hold to activate” then you can simply set a boolean flag to detect the current state and switch to the other state when pressed, the pseudo code looking something like:

var photoSphereOn = true;

pointerdown() {
    if(photoSphereOn) {
        PhotoSphere.visible(false);
        PhotoSphereOn = false;
    }
    else {
        PhotoSphere.visible(true);
        PhotoSphereOn = true;
    }
}

Hope this helps explain the logic :slight_smile:

Mark