-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
let riveInstance | ||
|
||
export function load_badger(){ | ||
riveInstance = new rive.Rive({ | ||
src: "/animations/badger.riv", | ||
canvas: document.getElementById("badger-canvas"), | ||
autoplay: true, | ||
artboard: "Artboard", | ||
stateMachines: "State Machine 1", | ||
}); | ||
pass_mousemove_events() | ||
|
||
} | ||
|
||
export function lazer_eyes(){ | ||
const inputs = riveInstance.stateMachineInputs('State Machine 1'); | ||
const lazerTrigger = inputs.find(i => i.name === 'anim_change'); | ||
lazerTrigger.fire() | ||
} | ||
|
||
export async function hide_badger(val){ | ||
await new Promise(res => setTimeout(res, 500)); | ||
|
||
const inputs = riveInstance.stateMachineInputs('State Machine 1'); | ||
if (inputs){ | ||
const hideInput = inputs.find(i => i.name === 'Hide'); | ||
hideInput.value = val | ||
} | ||
} | ||
|
||
export async function hide_badger_timed(){ | ||
await new Promise(res => setTimeout(res, 500)); | ||
|
||
const inputs = riveInstance.stateMachineInputs('State Machine 1'); | ||
if (inputs){ | ||
const hideInput = inputs.find(i => i.name === 'Hide'); | ||
hideInput.value = true | ||
|
||
await new Promise(res => setTimeout(res, 2000)); | ||
hideInput.value = false | ||
} | ||
} | ||
|
||
// the input field captures mouse events so a new event | ||
// needs to be created for the badgers eyes to follow the pointer. | ||
function pass_mousemove_events(){ | ||
const inputElement = document.querySelector('.program-input-field'); | ||
const badgerCanvas = document.querySelector('#badger-canvas'); | ||
|
||
inputElement.addEventListener('mousemove', function(event) { | ||
const newEvent = new MouseEvent('mousemove', { | ||
clientX: event.clientX, | ||
clientY: event.clientY, | ||
screenX: event.screenX, | ||
screenY: event.screenY, | ||
bubbles: true, | ||
cancelable: true, | ||
view: window | ||
}); | ||
badgerCanvas.dispatchEvent(newEvent); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters