Giter Club home page Giter Club logo

pixi.ninepatch's Introduction

PIXI.NinePatch

Rendering 9Patch containers on a PIXI stage.

Demo: http://mokgames.com/playground/pixi/ninepatch/ (Graphics from http://opengameart.org/content/ui-pack)

How to use

Simply load the pixi.ninepatch.js file after your pixi.js file.

<script src="pixi.js"></script>
<script src="pixi.ninepatch.js"></script>

Creating a 9 Patch Container

var ninepatch = new PIXI.NinePatch(width, height, image, useFrames);
stage.addChild(ninepatch);

width: The width of your 9Patch container.

height: The height of your 9Patch container.

image: The name of the used image. Use an asterisk for the the coutning number.

useFrames: If true, PIXI.Sprite.fromFrame will be used. If false then PIXI.Sprite.fromFrame will be used.

var ninepatch = new PIXI.NinePatch(100, 30, "img/yellow_button_0*.png", false);
stage.addChild(ninepatch);

The asterik in the file name will be replaced with the numbers 1 to 9.

[ 
  1, 2, 3,
  4, 5, 6,
  7, 8, 9
]

Adding content to the container

var ninepatch = new PIXI.NinePatch(100, 30, "img/yellow_button_0*.png", false);
stage.addChild(ninepatch);

ninepatch.body.addChild(sprite);

Restoring the DisplayObjectContainer scale behaviour

var ninepatch = new PIXI.NinePatch(100, 30, "img/yellow_button_0*.png", false, PIXI.NinePatch.scaleModes.DEFAULT);
stage.addChild(ninepatch);

or

var ninepatch = new PIXI.NinePatch(100, 30, "img/yellow_button_0*.png", false);
stage.addChild(ninepatch);

ninepatch.scaleMode = PIXI.NinePatch.scaleModes.DEFAULT;

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.