A ClojureScript wrapper for Phaser

Article by Richard Davey. Posted on 19th Aug 2015.   @phaser_

image

Dylan Paris has released phzr: "The phzr wrapper aims to provide a complete facade over the Phaser library. Namespaces in phzr should line up with the corresponding Phaser Javascript class hierarcy, i.e. Phaser.AnimationManager can be referenced at phzr.animation-manager. Instance methods for a class namespace always take an instance of that class as the first argument. Static methods do not, and are denoted by a trailing hyphen. If the corresponding Phaser class can be instantiated, the phzr namespace will also include a constructor function which follows the Clojure record constructor arrow naming scheme.

Along with the namespace wrappers, phzr also extends each Phaser class to implement a number of useful Clojure protocols. Currently, this allows functions like get, get-in, and seq to work on Phaser objects. As phzr develops, it may extend Phaser classes to more core protocols. When working with Phaser objects in phzr, only public properties are exposed through the protocol implementations. If a Phaser class has constants, the corresponding phzr namespace will have a const function which takes a keyword as an argument. All property and constant names have been converted to Clojure-style kebab-case keywords.

Additionally, Phaser classes implement the IPhaserObj protocol defined in the phzr.core namespace. Currently, this protocol specifies a function pset!, which allows phaser object properties to be mutated directly. The pset! function works similarly to aset, differing in that it accepts only the keyword-ized versions of the object property names, and will not allow mutations on properties marked as read-only or internal."

You can also follow the discussion on reddit.

Read More