loading tilemap data from external json in phaser ce

So tile maps are an important component of phaser ce that allows for making a map of tiles that contain among other things frame index values, that can then be skinned with sprite sheet. So tile maps are useful for many strategy and platform type games, and any other kind of project where they might come in handy. In this post I will be covering how to load external data from a json file that can contain all kinds of data for a tile map, such as frame index data and other useful properties. This can be done with the tilemap method of the loader in phaser ce.

Read More

Get an object value by path with the _.get Object method in lodash

So it is time for yet another lodash post, this time on the lodash _.get that allows me to get a value from an object by passing the object, and then a path in string format to the value that I want. There is also the lodash set method, but that is a matter for another post. This method of getting at properties of objects might prove to be a little more helpful compared to just getting properties the way one would in native javaScript in some cases, but still I can nit say this is one of the most compelling methods to support the use of lodash these days. In any case I will be writing about the lodash get method as well as other ways of getting at properties of object in general in this post.

In many frameworks a get method might do all kinds of things that involve getting something. For example in an http client library such as axios a get method might be a shorthand method for preforming a get request, in express the get method there is used for both getting an application setting as well as defining what need to happen for incoming get requests. However lodash is a general purpose core javaScript utility library that will work well in both a front end as well as back end environment, so the lodash get method has to do with just simply getting object property values.

With the lodash get method I can also pass an optional default value to the method in case the path to the value is undefined. So this might help to make the method a little more pointless, but there are still native ways of doing the same thing that I often find myself doing in place of the use of lodash get. It might also be a good idea to explore some other options for quickly getting values from an object in javaScript as well, so I will be writing about some vanilla js alternatives to _.get while I am at it.

Read More

The _.assign Object method in lodash, and alternatives

Looking over my content so far I am surprised that I have not yet wrote a post on _.assign in lodash, as well as the native alternative Object.assign methods. The _.assign method is one of many ways to go about combining a bunch of objects into a single object, and all around assign seems to work well for most situations, but there is a lot to be aware of when merging objects.

On the surface merging objects down together into one might seem to be a simple task, but often it is not so simple as one can run into all kinds of problems and concerns that have to do with things like copying be reference rather than value, and how to handle recursive references that might be present. So then the lodash assign method will work most of the time, but often there might be some other method that should be used such as merge, or one should at least clone objects that need to be cloned, or do more than just simply depend on one single method to get everything done all each time.

When it comes to objects they are copied by reference rather than value as wih primative values like numbers and strings, which can result in unexpected behavior if you are new to javaScript and are not aware of that nature surrounding objects. A new developer might assume that when they are assigning objects together they are creating a new object, and all the nested properties with values that are primitives, and additional objects, are new copies of the source objects. This might be the case when copying primitives, but it is not at all the case with objects. So the desired result of having a copy of nested source objects is not the case with the assign method.In lodash there are other options in lodash like merge, and also deep clone that can be used to get that effect if desired.

There is also the question of the prototype property of objects, and how that should be handled when combining two or more objects.

So in todays post I will be covering some use case scenarios of _.assign, and alternatives such as _.merge, and the native Object.assign method.

Read More

Starting out with Tile maps in phaser

When working with Phaser ce some projects might require the use of a time map. A tile map is a way of creating a an scene with a gird the contains a frame index for eac grid position, and each index refers to a standard texture in a sprite sheet. There is a lot to cover with tile maps, so this post will just be a quick overview of how to get started with them in phaser ce.

Read More

Tile Sprites in phaser for repeating backgrounds.

Tile sprites are a useful way to go about making a repeating background in a Phaser ce project. A tile Sprite is not to be confused with a tile map which is something completely different. For today I spent a little time playing around with tile sprites, and have found that if I ever want to set something up that involves one or more repeating backgrounds, I will want to use a tile sprite.

Read More