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

phaser3-interim-containers

v1.2.0

Published

Basic Interim Containers for Phaser 3.0.0 and up, until Containers officially land.

Downloads

9

Readme

Interim Containers for Phaser 3

Basic containers for Phaser 3 until they officially land.

Phaser 3 has officially been released, but due to time constrains, some features have been left for now. One of the most important features that I am missing is Containers. They are similar to groups, but they allow you to manipulate them as if they were a sprite. For example, you can set their alpha, rotation, position, etc. Groups are mainly aimed at organizing your sprites, and do not have these features.

This repository will be marked as deprecated as soon as Phaser launches their version of Containers, which will no doubt be superior. Code was written in old-school javascript as much as possible, to avoid the need for transpiling.

Prerequisites

Interim Containers expects the Phaser object to be available globally. This only works with Phaser 3.0.0 and up (tested up to 3.1.0).

Installing

NPM

npm install --save phaser3-interim-containers

Yarn

yarn add phaser3-interim-containers

Bower (you should move to yarn)

bower install phaser3-interim-containers

Stoneage

Simply download the index.js file and include it in your HTML file.

Usage

Interim Containers function very similar to Groups, with two important gotcha's:

  • You must use addChild() or createChild() on the Container, instead of add() and create(). They behave exactly as you'd expect. This is due to the way Phaser's Class system and inheritance works. I couldn't find a clean way to inject my own code there.
  • Use child._containerProps.property instead of directly changing a child's properties.

Supported properties for both the Container and che children (please update this list when submitting a PR):

  • x
  • y
  • alpha
  • rotation
  • scale
  • flipX
  • flipY

Starting at 1.2.0, you are able to provide a list of properties that will be watched using the watch option. Please see the example. Doing so will increase the performance of containers that are updated all the time (for example, using tweens). If you do not provide this option, all supported properties will be watched.

Example


var container, sprite1, sprite2;

new Phaser.Game({
	scene: {
		create: function(){

			//Creating a container (options are optional)
			container = this.add.container({
				x:100, 
				y: 50, 
				alpha: 0.9, 
				rotation: 1.3, 
				watch: ['x', 'y', 'rotation','alpha']
			});

			//Create a sprite directly on the container, just as you would with group.create
			sprite1 = container.createChild(200, 200, 'spaceship');

			sprite2 = this.add.sprite(200, 200, 'spaceship');
			container.addChild(sprite2);

		},

		update: function(delta){

			//These are all supported - they don't all make sense in this context though ;)
			container.x += 10;
			container.y += 10;
			container.alpha -= 0.01;
			container.rotation += 0.01;
			container.scale += 0.01;

			// You can also alter the children directly and 
			// everything will work out.
			// However, since their properties are overwritten 
			// as soon as you update the container, you'll have
			// to alter the properties on the _containerProps 
			// object (which is automatically added for you by the container):
			// All of these values are relative to the container.

			sprite1._containerProps.rotation -= -0.1;
			sprite1._containerProps.x = 100;
			sprite1._containerProps.y = 50;

		}
	}
});

Todo

  • Example code could use some work
  • Support more properties
  • Find a clean way to support changing values on Sprites directly, without breaking or littering everything
  • Confirm that Tweens work, and make them work if they don't

Contributing

Feel free to submit a pull request or open an issue with suggestions or ideas.

License

This project is licensed under the MIT License

Credits

Created by Nick Kamer, Ziao on Github, or [email protected]. Huge shoutout to the guys at Photonstorm for creating this awesome framework!