Skip to content

Instantly share code, notes, and snippets.

@nikki93
Created November 30, 2016 23:11
Show Gist options
  • Save nikki93/9a20c3c8b4b327fb87146d1f0c200468 to your computer and use it in GitHub Desktop.
Save nikki93/9a20c3c8b4b327fb87146d1f0c200468 to your computer and use it in GitHub Desktop.
'use strict';
import React from 'react';
import { GLView } from 'exponent';
export default class BasicScene extends React.Component {
static meta = {
description: 'PIXI Basic Scene',
};
render() {
return (
<GLView
style={this.props.style}
onContextCreate={this._onContextCreate}
/>
);
}
_onContextCreate = (gl) => {
gl.enableLogging = true;
window.addEventListener = () => {},
navigator.userAgent = 'Exponent';
global.document = {
createElement: () => ({
style: {},
getContext: () => ({
drawImage: () => {},
fillRect: () => {},
getImageData: () => null,
}),
}),
addEventListener: () => {},
};
const PIXI = require('pixi.js/src/index');
const width = gl.drawingBufferWidth;
const height = gl.drawingBufferWidth;
const renderer = new PIXI.WebGLRenderer(width, height, {
view: {
width, height,
addEventListener: () => {},
removeEventListener: () => {},
getContext: () => gl,
},
context: gl,
});
const animate = () => {
requestAnimationFrame(animate);
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.flush();
gl.endFrameEXP();
gl.enableLogging = false;
};
animate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment