Giter Club home page Giter Club logo

phaser-3-palette-swapping-example's Introduction

Phaser 3 Palette Swapping Example

Example of using palette swapping on a spritesheet in Phaser 3.

How It Works

This initial idea came from this article:
http://laxvikinggames.blogspot.com/2015/01/build-dynamic-texture-atlas-in-phaser.html

The palette swapping in this example is achieved by taking an image that contains palette data then going through a spritesheet and switching the matching pixels from the original palette to the new palette.

Our "palette data" image is a small image consisting of each unique color we want to replace and their replacements. Each color is a single pixel, and each row represents an individual palette.

Palette Example

We then define a config containing the relevant information for creating the necessary spritesheets and animations after the palette swapping is performed.

var animConfig = {
    paletteKey: 'link-palette',                         // Palette file we're referencing.
    paletteNames: ['green', 'red', 'blue', 'purple'],   // Names for each palette to build out the names for the atlas.
    spriteSheet: {                                      // Spritesheet we're manipulating.
        key: 'link',
        frameWidth: 32,                                 // NOTE: Potential drawback. All frames are the same size.
        frameHeight: 32
    },
    animations: [                                       // Animation data.
        {key: 'walk-down', frameRate: 15, startFrame: 0, endFrame: 9},
        {key: 'walk-left', frameRate: 15, startFrame: 10, endFrame: 19},
        {key: 'walk-up', frameRate: 15, startFrame: 20, endFrame: 29}
    ]
};

Once the spritesheets and animations have been built, we can then use them in our game as we need!

Demonstration

phaser-3-palette-swapping-example's People

Contributors

colbydude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

phaser-3-palette-swapping-example's Issues

Add Texture Atlas?

Hi @Colbydude ! I recently tried out your sprite sheet version of the 3.20.1 update & I must say, This project is AMAZING! PLEASE keep up the WONDERFUL work!

I really don't want to have to re-color all my Texture Atlas sprites & I would really like to use Palette switcher on my Character Texture Atlases.

I would be MORE than happy to beta test it for you!

Thank you SO much & keep up the GREAT work! =)

PLEASE REWRITE FOR PHASER 3.20.1!!!

@Colbydude Hello, I came across your AMAZING demo & I would really like to integrate it into my project, but 2 small problems. 1 ) It uses an older version of phaser 3. & 2 ) I use texture atlases for player. Not Sprite sheets.

Could you please be so kind as to rewrite this for 3.20.1?

Thank you SO much & have a GREAT day!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.