Skip to content

Instantly share code, notes, and snippets.

View netcell's full-sized avatar

Nguyễn Tuấn Anh netcell

View GitHub Profile
@netcell
netcell / abc
Created July 17, 2013 12:24
abc
abc
@netcell
netcell / gist:60097d0661ad2f74a258
Last active February 1, 2020 13:39
Camera for Phaser
var game = require('../common/game');
class Camera extends Phaser.Group {
constructor({x = 0, y = 0}) {
super(game);
var {world, physics, camera} = game;
var {centerX, centerY, bounds} = world;
this.scale.setTo(1, 1);
//...
, game = new Phaser.Game(properties.size.x, properties.size.y, Phaser.AUTO, 'game');
// Automatically register each state.
_.each(states, function(state, key) {
game.state.add(key, state(game));
});
//...
class Joystick extends Phaser.Sprite {
constructor(x, y) {
super(game, 0, 0, 'background');
this.anchor.setTo(0.5, 0.5);
/* Pin indicator - what players think they drag */
this.pin = game.add.sprite(0, 0, pin);
this.pin.anchor.setTo(0.5, 0.5);
this.addChild(this.pin);
/* Invisible sprite that players actually drag */
var dragger = this.dragger = game.add.sprite(0, 0, null);
constructor(x, y) {
...
this.isBeingDragged = false;
dragger.events.onDragStart.add(this.onDragStart, this);
dragger.events.onDragStop.add(this.onDragStop, this);
...
}
onDragStart(){
this.isBeingDragged = true;
}
@netcell
netcell / VirtualJoystick
Created April 3, 2015 05:10
Phaser Virtual Joystick
var normalize = Phaser.Point.normalize;
var zero = new Phaser.Point(0, 0);
class Joystick extends Phaser.Sprite {
constructor({x, y, holder, pin}) {
super(game, 0, 0, holder);
this.anchor.setTo(0.5, 0.5);
this.fixedToCamera = true;
this.cameraOffset.setTo(x, y);
@netcell
netcell / PhaserFillscreen.js
Last active February 22, 2024 23:02
Setting for Phaser.js to fill the screen on web browsers and Cocoon.js
/** Config part */
var FIXED_SIZE = 600;
var FIXED_MEASURE = 'Height';
/** Name maping */
var fixedName = FIXED_MEASURE;
var resName = fixedName === 'Height' ? 'Width' : 'Height';
var FIXED_NAME = fixedName.toUpperCase();
var RES_NAME = resName.toUpperCase();
@netcell
netcell / AddPlugin.js
Last active September 15, 2015 09:24
Phaser Inspector Plugin Example
Phaser.Plugin.Inspector.DetailPlugin.add(Phaser.Plugin.Inspector.DetailPlugin.FrameRenderPlugin);
function getRandomShapes(width, height) {
var shapeArray = new Array();
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var topTab = undefined;
var rightTab = undefined;
var bottomTab = undefined;
var leftTab = undefined;
@netcell
netcell / Type.php
Created May 15, 2016 08:40
gds-php wrapper Type definition
<?php
namespace App\Datastore\Abstracts;
class Type {
const String = 1;
const Integer = 2;
const Datetime = 3;
const Float = 4;
const Boolean = 5;