Building Custom Extensions: The Twin Stick Training Range
Time to read: 2 minutes
This is the first post in a series where I'll make an extension on an interesting topic in a day or two. Afterward, I'll share the source code and a short write up with some details about the extension.
TwilioQuest is all about having fun while learning. With the new extension authoring tools, we've created there are more opportunities for fun than ever. For this first post, I wanted to focus entirely on the fun side of things. Without further ado, let me present this state of the art training simulation where you can train to defeat Cedric's evil twin, Fredric.
Check out the source on GitHub!
Prototyping new features using world.__internals
We've talked on the team about how many cool things we could do in TwilioQuest if we could spawn arbitrary objects while the game is running. I wanted to explore what it takes to get that going in the current version of the authoring tools.
We don't have any sort of "spawn" feature built in yet, so I wanted to make use of our new world.__internals
feature to prototype. This __internals
object contains a reference to the internal level object that controls all of TwilioQuest. With this reference, we can access the underlying object creation functions on the internal Phaser (the engine we use to build TwilioQuest) game instance.
Once we had access to the Phaser game inside an extension, I had to find a good example of top down shooting. I decided to use this Phaser demo as a base for this extension. I adapted the core shooting functionality here to allow the player and the cannons to shoot at each other. The player shoots in response to mouse clicks and the cannons shoot on an interval.
This is the first example we have of making use of the world.__internals
feature. It's pretty powerful, but it requires some decent knowledge of Phaser to get things done.
Where do we go from here?
This extension was really fun to build and an exciting direction to explore. I'm hoping to get some of this logic into some handy world functions so that authors don't need to know how to use Phaser themselves.
I learned that creating a dynamic object in the latest version of the TwilioQuest authoring tools involves a lot of messing around in Phaser-land. We want to make it a lot more accessible to create moving objects in TwilioQuest in the future. This will probably take the form of a new set of world.spawn
APIs.
Another important thing that this extension required is more advanced control over how player input works. Phaser exposes these events to us, so we'd probably add some events like onKeyDown
and onMouseClick
to the set of events we currently have in TwilioQuest already.
It's time to fight Fredric!
Get out there and start training, Operator!
Download the latest release from the twin stick demo repository and unzip it into your extensions folder. Come chat with us in the TwilioQuest Discord once you've tried it and want to build your own extension.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.