Skip to content

Instantly share code, notes, and snippets.

import Phaser from 'phaser';
const playerPositions = {
1: { x: 112, y: 112 },
2: { x: 1376, y: 160 },
3: { x: 2000, y: 48 },
4: { x: 2176, y: 144 },
};
export class GameScene extends Phaser.Scene {
@samme
samme / hex.js
Last active April 26, 2024 15:47
Hexadecimal number/string conversions
// 0x00000f (15) to '#00000f'
'#' + (0x00000f).toString(16).padStart(6, '0')
// '#00000f' to 0x00000f (15)
parseInt('0x' + '#00000f'.slice(1))
@samme
samme / GlobalClock.js
Created March 13, 2024 17:09
Global clock plugin for Phaser 3
/* global Phaser */
// GlobalClock
// Modified from Phaser.Time.Clock by Richard Davey © 2013-2023 Photon Storm Ltd. <https://opensource.org/licenses/MIT>
class GlobalClock {
constructor(pluginManager) {
this.pluginManager = pluginManager;
this.game = pluginManager.game;
this.now = 0;
@samme
samme / gameConfig.js
Last active February 6, 2024 19:27
Phaser 3 with ES modules
export const gameConfig = {
scene: {
create: function () {
this.add.text(0, 0, "Hello world");
}
}
};
@samme
samme / gameConfig.js
Last active February 6, 2024 19:27
Phaser 3 global with ES modules
export const gameConfig = {
scene: {
create: function () {
this.add.text(0, 0, "Hello world");
}
}
};
@samme
samme / ScaleX.js
Last active April 24, 2020 15:55 — forked from nicoptere/ScaleX
Performs a scale2x and scale3x operation on a HTML canvas
/*
JavaScript port of <http://scale2x.sourceforge.net/algorithm.html>
*/
var scaleX = (function (exports) {
function getPixel32(data, x, y, w) {
var id = (x + y * w) * 4;
return (data[id] << 16) | (data[id + 1] << 8) | data[id + 2];
}
@samme
samme / base.js
Last active July 18, 2023 22:10 — forked from tickle-monster/base.js
Phaser 3 BaseScene
export class BaseScene extends Phaser.Scene
{
constructor(config)
{
super(config);
}
init()
{
this.user = this.registry.get('user');
@samme
samme / dungeon.txt
Last active March 29, 2020 00:06
Dungeon. See “Raw”
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░▓ ▓ ▓░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░▓ ▓░░░░░░░░░▓ $ ◆ ▓░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░▓ ⚜︎ ▓░░░░░░░░░▓ ▓ ⚒︎ ▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░
░░░░░░░░░▓ $ $ ▓▓▓▓▓▓▓▓▓▓▓ ▓ ▓░░▓ ⚱︎ ▓░░░░░
░░░░░░░░░▓ ▓ ⚜︎ $ ▓▓▓◇▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░▓ ▓░░░░░
░░░░░░░░░▓ ▓ ⚑ ▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓░░░░░
░░░░░░░░░▓ ◆ ▓ ▓ ▓ ▓░░░░░
░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ◆ ⚘ ▓ ◇ ▓░░░░░
@samme
samme / main.js
Last active February 21, 2020 19:35
Switch audio
var music = [
{
key: 'bgMusic',
url: 'assets/TownTheme.mp3',
config: {
volume: 0.1,
loop: true
}
},
{
@samme
samme / readme.md
Last active January 23, 2020 01:24
Phaser.Display.Color conversions
input / output ColorObject Color† HSVColorObject number† string
(h: number, s: number, l: number) HSLToColor
(h: number, s: number, v: number) HSVToRGB HSVToRGB
(r: number, g: number, b: number, a: number) GetColor32
(r: number, g: number, b: number) RGBToHSV RGBToHSV GetColor RGBToString
ColorObject ObjectToColor, ValueToColor
string '#RGB' '#RRGGBB'