Skip to content

Instantly share code, notes, and snippets.

View photonstorm's full-sized avatar

Richard Davey photonstorm

View GitHub Profile
@photonstorm
photonstorm / compressed-textures.js
Last active April 15, 2018 13:00
Phaser Compressed Texture Support
// Phaser 3 has the new Loader method, texture:
load.texture('factory', {
etc1: 'assets/factory_etc1.pkm',
s3tc: 'assets/factory_dxt1.pvr',
pvrtc: 'assets/factory_pvrtc.pvr',
truecolor: 'assets/factory.png'
});
// You can also use load.image:
@photonstorm
photonstorm / phaser-multi-texture-example.js
Created September 23, 2016 17:05
Phaser 3 Multi Texture Example
var game = new Phaser.Game(800, 600, Phaser.WEBGL_MULTI, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('clown', 'assets/sprites/clown.png');
game.load.image('beball', 'assets/sprites/beball1.png');
game.load.image('coke', 'assets/sprites/cokecan.png');
game.load.image('asuna', 'assets/sprites/asuna_by_vali233.png');
@photonstorm
photonstorm / state-swap.js
Created March 3, 2016 21:24
How to keep the same Phaser Sprite through a change in State
var PewPew = {
// Our global Sprite, shared between States
spaceship: null
};
PewPew.Preloader = function () {};
PewPew.Preloader.prototype = {
@photonstorm
photonstorm / stopSidewaysVelocity.js
Created February 24, 2016 11:39 — forked from ShimShamSam/stopSidewaysVelocity.js
Phaser Physics - Stop sideways velocity
/**
* Negate sideways velocity on an object being acted upon by a Phaser physics engine.
* The primary use for this is to simulate vehicle movement by negating "drift" when the vehicle turns.
* @param {Phaser.Sprite} sprite The sprite whose sideways velocity you want to negate
*/
function stopSidewaysVelocity(sprite) {
// Recycle the same object to conserve memory
if(!stopSidewaysVelocity.sideways) {
stopSidewaysVelocity.sideways = {};
}
@photonstorm
photonstorm / gc.js
Last active November 19, 2015 17:04
gc test
// The following code, on its own (with nothing else)
// generates ~500 KB of gc every ~2.5 seconds in 49.0.2568.0 canary (64-bit / Windows 7)
// Update: Appears it's an issue with Dev Tools: https://code.google.com/p/chromium/issues/detail?id=120186
// Using JS Profiler creates lots of garbage in the JS Heap. Wonderful.
function update (now) {
window.requestAnimationFrame(update);
@photonstorm
photonstorm / books.md
Last active March 10, 2018 15:16
Game Art Books

Push Start (very good, mostly retro / pixel art) Amazon

Game Art (40 Interviews, covers about 2000+) Amazon

The Art of Naughty Dog (sublime!) Amazon

Game specific:

@photonstorm
photonstorm / gist:0ba8b8edcae55400b31f
Created October 8, 2014 14:21
iOS7 / iOS8 full-screen madness workaround
<!doctype html>
<html lang="en">
<html><head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta charset="UTF-8">
<title>iOS7 fullscreen test</title>
<meta name="description" content="a proof of concept workaround for some iOS7 madness.">
@photonstorm
photonstorm / gist:9d92f19507df7462ddd5
Created August 12, 2014 16:30
Phaser Pointer Lock example
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('ball', 'assets/sprites/shinyball.png');
}
var sprite;
function go(){
mycanvas.fill('#000000');
logo.draw(mycanvas,0,0);
mycanvas.line(0,90,640,90,6,'#FFFFFF');
mycanvas.line(0,296,640,296,6,'#FFFFFF');
myscrolltext.draw(296+10);
var front = new Array();
var back = new Array();
var x = 150+100*Math.cos(angleb);
@photonstorm
photonstorm / gist:5300530
Created April 3, 2013 11:49
array shuffle
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;