Hi,
Made my first Phaser 3 game: Spaceinvaders. I am fairly new to Javascript and new to Phaser. I really like to have some feedback on:
- API usage
- best practices
- codding standards
- tips
Hi,
Made my first Phaser 3 game: Spaceinvaders. I am fairly new to Javascript and new to Phaser. I really like to have some feedback on:
Very smooth. I like it. Level 3 is already very hard
As for coding, maybe add some comments, and try to keep your files small. GameScene.js has a lot going on, easy to lose the overview…
Hi @bit33,
After seeing your code, there are two things that in my humble opinion could be improved (GameScene.js):
this.cursors = this.input.keyboard.createCursorKeys();
In more complex games these changes would be more relevant.
Congratulations for your first game with Phaser !! .
Regards.
Thanks jjcapellan,
I tried to refactor my code to use pools/groups for my gameobjects. But I can not make it behave the same way as it does when I still used .destroy(). In stead of destroy I now use:
alien.setActive(false);
alien.setVisible(false);
But the other active aliens will still bumb into the old one and don’t move properly. So I tried moving them offScreen:
aliens.setPosition(2000,2000);
But now they end up in the bottom corner and still get velocity when I call group.setVelocityX(20);
So what is the best way to replace the alien.destroy() call then using pools?
The aliens group elements have a body, so you should use disableBody :
alien.disableBody (true, true);
This is equivalent to:
alien.body.enable = false;
alien.setActive (false);
alien.setVisible (false);
For the same reason, setPosition() produces unexpected results. An appropriate method would be body.reset:
alien.body.reset (x, y);
Good luck !!
Thanks jjcapellan,
that was just what I needed. Have refactored the code, now it recycles all gameobjects, extracted some classes out of main game scene to make the scene code more compact and comprehensive.