Extending Kiwi Objects in Javascript

If you want to extend Kiwi.js objects, such as Sprites, to create reusable specialised game objects, you can use your favourite Javascript techniques to do so. If you want to mimic classical inheritance Kiwi.js provides an easy way to do this.

Here is an example of extending the Kiwi.GameObjects.Sprite class in both Typescript and Javascript.

Typescript

 

Javascript

If you’re using Javascript you can use the Kiwi.extends function to create the subclass. The extends function uses a technique of extending objects identical to Typescript.

 

This is functionally identical to the Javascript that Typescript would compile to do the same thing. If you prefer you can use the function in the same way too. It’s purely a matter of preference.  It looks like this:

 

Share the joy

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">