Right Click Actions


(Jonathan Bowman) #1

I want to create a right click action that jumps to the next scene. How the heck do I do this?


Linking to a specific scene from inside and outside of a Tumult Hype document
#2

This can be done with JavaScript. Basically, you’d need an event listener and detect a right click.

It requires custom JavaScript code, but it’s possible. I added a right click feature to one of my (unfinished) games.

https://photics.com/games/broom


(Jonathan Bowman) #3

I did it! Thanks


(Jonathan Bowman) #4

Can I see some javascript that tells me how to go to a specific scene? I have a right click event set up, but I want a right click to trigger a scene change.

What’s the javascript command for go to scene “x” on right click?

Thanks:)


#5

When you edit JavaScript in Hype, you should see the Hype API stuff at the bottom – with a section for scenes. More documentation is here…

…but basically it’s…

hypeDocument.showSceneNamed(sceneName, optionalTransition, optionalDuration)


#6

You would run this ‘On Scene Load’ to capture the right click, and use it to go to a named scene:

window.oncontextmenu = function (){
  hypeDocument.showSceneNamed('Scene 2', hypeDocument.kSceneTransitionCrossfade, 1.1);
}

rightclick.zip (18.3 KB)


(Jonathan Bowman) #7

WOW!!! Okay, that was pure perfection. Thanks!


(Jonathan Bowman) #8

How do I hide the browser right click menu? It keeps showing up.


#9

Add one line:

window.oncontextmenu = function (){
  hypeDocument.showSceneNamed('Scene 2', hypeDocument.kSceneTransitionCrossfade, 1.1);
// this line means: Don't do what is normally done:   
return false;
}

Here’s a nice post about what return false; does:


(Jonathan Bowman) #10

That worked Daniel! Thanks!