Using Phaser.Signal to use and create events in phaser

Events are a big part of phaser ce game development, and the Phaser.Signal class is the phaser ce standard way of creating, and making use of events in phaser ce. There are many instances of Phaser.Signal to begin with in phaser that can be used to define some handers for when those events occur, but the class can also be used to define events as well. In this post I will be giving some use case examples of Phaser.Signal, including how to make one of my own, but I will not be covering all the different events that are built in.

Read More

The unique id method in lodash, and alternatives

I am writing more content on lodash this month for now, and while I was at it I have noticed that I did not get around to _.uniqueId yet. As the name of the method suggests the method will return a unique value each time the method is called, so then it can be used as a way to set some kind of unique id values for an object of one kind or another. The method addresses something that comes up once in while now and then when developing projects, so it deserves a post on the subject.

Also in these lodash posts I often take a moment to brush up on how hard it is to go about making a vanilla js solution, or if there are native methods that can be used, and as such this post will be no exception. making this kind of method is not all that hard when it comes to making a kind of custom utility library from the ground up. Also such methods might prove as a great simple starting point for learning a thing or two about closures in javaScript. So lets take a look at _.uniqueId, and some other solutions for generating unique ids.

Read More

Creating an array of numbers with _.range in lodash

Sometimes when working on a javaScript project there is a need to create a range of numbers in an array, with lodash there is the _.range method than can be used to quickly make a range of numbers. The method is fairly easy to use so this should be be quick when it comes to just using the single lodash method. However there is also the general idea of not using lodash anymore as there are often native javaScript solutions for doing many of these tasks actually. So on top of going over a few quick examples of the lodash rage method I will also be looking into some additional examples that make use of just native javaScript by itself.

Read More

The lodash _.extend method for combining objects, and alternatives

When working with two or more objects there may come a need to combine them all together into a single object, and when doing so things can get a little confusing. There are what is often referred to as the objects own properties, then there are inherited properties, in addition there is also ways of making hidden properties by making use of the Object define property method. If that was not enough then there is also the nature of copying by reference rather than value with objects in javaScript, and also things like how to go about handing any and all recursive references, mainly the question of if they should refer to the new object, or should they be preserved as is.

In this post I will be writing about the lodash object method known as _.extend, and how it compares to other methods in lodash that are used for combining objects together. Hopefully this post will help eliminate some confusion that you might have with combining objects in javaScript, or reinforce what you all ready know. If not in any case this is a somewhat complicated topic, but they only way to make process with it is to just start reading up on it, and also toy around with some examples at a first hand level.

Read More

The lodash forIn method

The _.forIn method in lodash is a helpful tool, for looping over both own, and inherited properties in an Object in a javaScript environment. There are a number of other ways to go about looping over the various properties of objects though with both lodash, as well as with just plain old javaScript by itself though. In lodash there is the lodash for each collection method that will loop over all of the own properties of an object collection in general, and in native javaScript there is the array for each method that will loop over all the numbered, public own properties of an array. There is also not a native for in loop in javaScript itself also as well that can be used in modern javaScript specs. So then with that said, in this post I will be covering a basic use case example of _.forIn, and how it compares to other lodash, and vanilla js methods of looping over object properties in javaScript.

Read More