npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

phaser-responsive

v1.3.3

Published

Adds responsive objects that can be pinned to Phaser!

Downloads

65

Readme

Phaser Responsive

Phaser-Responsive plugin adds images/sprites/buttons/groups that can be pinned to corners/sides/center!

Getting Started

First you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.

npm install phaser-responsive --save-dev

Next up you'd want to add it to your list of js sources you load into your game

<script src="node_modules/phaser-responsive/build/phaser-responsive.js"></script>

Usage

Load the plugin

You still need to load the plugin in your game. This is done just like any other plugin in Phaser

game.plugins.add(Fabrique.Plugins.Responsiveness);

The plugin will patch your Phaser game with additional load/add/make methods so the responsive objects fits up in Phaser like any normal object!

Create responsive objects

Add an image, text, button or sprite as you would in Phaser, adding 'responsive' in front of the name. When creating them, add a pin position in the parameters which can be either the middle of the canvas or one of it's edges.

The available pin positions are:

  • topLeft
  • topCenter
  • topRight
  • middleLeft
  • middleCenter
  • middleRight
  • bottomLeft
  • bottomCenter
  • bottomRight

Then, set an anchor point to align the corner of the image/text/button/sprite with the corner of the canvas.

sampleImage = game.add.responsiveImage(5, 5, 'square', null, Fabrique.PinnedPosition.bottomRight);
sampleImage.anchor.set(1, 1);

Set scaling for objects

By setting the landscape/portrait scaling for an object, the object will be scaled a certain percentage of the width or height of the total game. By default the width will be used, if you want the object to scale according to the height, you can pass the second parameter as false. The scaling will only be done on mobile, if you want the objects to be scaled when your game is running on desktop you can pass the third parameter as true.

In the next example the sampleImage will always be 50% of the game width in landscape and 50% of the game height in portrait.

sampleImage = game.add.responsiveImage(5, 5, 'square', null, Fabrique.PinnedPosition.bottomRight);
sampleImage.setLandscapeScaling(50, true, false);
sampleImage.setPortraitScaling(50, false, false);

Relative pinned position

If you want the offset of your objects to be relative to the game size you can also pass a pinned position and an x and y offset to the landscape/portrait scaling.

In the next example the sampleImage will always be 20% of the game width and be positioned to the middle left. When the image is the original size the offset will be 100px, when the image is scale the 100px will be relative to the scaling.

sampleImage = game.add.responsiveImage(5, 5, 'square', null);
sampleImage.setLandscapeScaling(20, true, false, Fabrique.PinnedPosition.middleLeft, 100, 0);
sampleImage.setPortraitScaling(20, true, false, Fabrique.PinnedPosition.middleLeft, 100, 0);

Changelog

1.3.0

  • Pinned position offset is now relative to portrait/landscape scaling

1.2.0

  • Objects can now store their portrait/landscape special scaling values

1.1.0

  • Added static dynamic scaling method

1.0.1

  • Initial release

Disclaimer

We at OrangeGames just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed some awesome objects that needed to be responsive in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!