emshuttles Posted October 3, 2017 Share Posted October 3, 2017 Two classmates and I are trying to build a Tetris RPG in which clearing a row gives you mana, which can be used to cast damaging spells at the enemy. Basically, your typical puzzle RPG mobile game, except you get to choose your attacks and when to do them. We started out by building a vanilla Tetris game in the main game state file. Once that was finished, we tried creating a Tetris class to put all of that logic into. Then, we ran into a problem: we can't use the Phaser methods (e.g., creating sprites, detecting key presses) in the Tetris class, so we had to leave some functions behind in the game state file. What is the most elegant solution to this? Could we have a Tetris game object running within a more general 'battle' game that would also handle the enemy and player logic? Or is there some other way to use Phaser methods in a JS class? Link to comment Share on other sites More sharing options...
mattstyles Posted October 4, 2017 Share Posted October 4, 2017 You can extend the main Phaser object and create your own object from that, for example, using esnext class syntax: class Tetris extends Phaser.Game {} note: this is just sugar, if you're not writing using newer syntax then doing this is trivial also, just takes a few more lines of code. You can also do this with Phaser states too if you like/need. Link to comment Share on other sites More sharing options...
samme Posted October 5, 2017 Share Posted October 5, 2017 Or you can just pass the game instance to your class's constructor. Link to comment Share on other sites More sharing options...
emshuttles Posted October 5, 2017 Author Share Posted October 5, 2017 Thank you! There's a lot to learn about Phaser, but the tutorials we could find have been too simple to be very useful. Link to comment Share on other sites More sharing options...
samid737 Posted October 6, 2017 Share Posted October 6, 2017 The examples are often extremely useful (old syntax):https://phaser.io/examples/v2/sprites/extending-sprite-demo-1 Link to comment Share on other sites More sharing options...
Recommended Posts