Skip to content

Instantly share code, notes, and snippets.

@blopa
Last active November 8, 2020 17:13
Show Gist options
  • Save blopa/d893a61e5065aa5ddf853497d5e7f4fb to your computer and use it in GitHub Desktop.
Save blopa/d893a61e5065aa5ddf853497d5e7f4fb to your computer and use it in GitHub Desktop.
class HtmlFileInput {
constructor({
scene,
spriteKey,
}) {
// Phaser's parent HTML element
const mainElement = scene.sys.game.canvas.parentElement;
// create html input type
const fileInput = document.createElement('input');
fileInput.setAttribute('type', 'file');
fileInput.setAttribute('accept', '.json');
fileInput.setAttribute('id', spriteKey);
// TODO this stylings
fileInput.style.position = 'absolute';
fileInput.style.top = 0;
fileInput.style.display = 'block';
fileInput.style.marginTop = '-400px';
mainElement.appendChild(fileInput);
this.setFileInput(fileInput);
this.setScene(scene);
}
setFileInput = (fileInput) => {
this.fileInput = fileInput;
}
setScene = (scene) => {
this.scene = scene;
}
}
export default HtmlFileInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment