Getting a sprite that is closest to another sprite in a group in phaser

When working with a group of sprites in a phaser ce project a common task that comes up is to get a reference to a sprite in a group that is closest to another sprite. There are many ways of doing this that involve using a distance formula when looping over all active children in the group, however there is also a group method called group.getClosestTo that can be used to quickly get that sprite in question.

Read More

Aligning Sprites in a group into a grid in phaser ce with group.align

If you have a collection of sprites in a phaser ce project and you want to align them into a grid, it is not to hard to just do it by working out a method. However why bother with that when there is a method that is part of the group class itself? There is of course group.align that can be used to do this, and it does it fairly well with some nice features that can be used to tweak things a bit. Never the less in this post I will be writing about some examples that have to do with aligning sprites, and other display objects in a group in phaser ce.

Read More

The create method in lodash, and native alternatives

So in javaScript the Object.create method or _.create in lodash might come up now and then in many code examples. These teo methods are ways of creating a new object with a given object that will function as the new objects prototype object. The prototype object is something that is separate from what is often called the own properties of the object, and with that said both of these methods also provide a way to create open properties for the new object also. However there are some very important differences between the two methods, the lodah create method works the way that I would want such a method to work in most cases. However the native method allows for a greater degree of flexibility when it comes to defining own properties of the object including the ability to make some of the own properties not enumerable for example.

If you are still new to javaScript the prototype is something that you should become familial with at some point sooner or later, as it is a major part of javaScript development. In this post I will be giving some use case examples, and hopefully give at least a basic idea of what the create object method is all about.

Read More

Basic scrolling with a tile map in phaser ce

So there are many ways to go about handing scrolling a tilemap in phaser ce, in this post I will be writing about one of the simplest ways to go about doing so that I have come across so far. This way of doing it should work okay for most projects, but with projects where map data is being generated on the fly at run tile, or projects that involve a very large collection of map data across many files, they way of doing here might not cut it.

Read More

Setting collsion in a tilemap with phaser

These days I have been playing around with tilemaps a lot in phaser ce. When doing so for some projects I will want to set collision detection for some tiles. In this post I will be covering doing just that with a method that woulds by setting collision tile index values by giving what index values I do not want to result in collision. This can be done with a helpful little method in the tilemap class called Tilemap.setCollisionByExclusion

Read More