Search the Community
Showing results for tags 'factory'.
-
Hi everyone, I'm working on a javascript clone of superhexagon (https://www.superhexagon.com/) in order to learn to use Phaser 3. I was wondering what was the best way to generate the same shape multiple time with some rotation tweek and animate them. I need generate them, display them, once they display I need to be able to rotate them and scale them down. Once their scale <= 0 I need to hide and destroy them. I know I need to build a kind of Factory but I can't figure out how to do it with gameObj.add.arc Could you point a part of doc or source code I can dig in to find a solution? I created a pen here https://codepen.io/paulbonneau/pen/KGGbGO Thanks in advance ! Paul.
- 3 replies
-
- generation
- factory
-
(and 2 more)
Tagged with:
-
Hey, I got a lot of ES6 classes for my game, so I use a factory, that is hooked into phaser as a plugin. Complete code below. However when I do 'const PLAYER = this.add.player(x,y);' it does not return the player object and the constant PLAYER is null. Can someone help me out here? What am I missing? class ObjectFactory extends Phaser.Plugins.BasePlugin { constructor(pluginManager) { super(pluginManager); pluginManager.registerGameObject('player', this.createPlayer); pluginManager.registerGameObject('overlay', this.createOverlay); } createPlayer(x, y) { return this.displayList.add(new Player({ scene: this.scene, x: x, y: y })); } createOverlay(x, y, w, h) { return this.displayList.add(new Overlay({ scene: this.scene, x: x, y: y, w: w, h: h })); } } Plugin config: plugins: { global: [ { key: 'Factory', plugin: ObjectFactory, start: true } ] }, cheers
- 10 replies
-
- sprite
- javascript
-
(and 1 more)
Tagged with:
-
Hi, I'm coming from flash/flixel perspective. When I'd need spawn enemies or track some objects and draw something on them repeatedly, I used to create a class instance which contains and watches objects, and mostly use it as kind-of factory pattern as well to generate objects too. I was doing this by extending groups in Flixel. I know groups are pretty similar in Phaser too. But possibly because of my lack of experience on OOP javascript, I haven't found a nice way to extend groups. Im extending groups this way; var ElementalSpawner = function(game,squad) { Phaser.Group.call(this,game);};ElementalSpawner.prototype = Object.create(Phaser.Group.prototype);ElementalSpawner.prototype.constructor = ElementalSpawner;Until this point everything is great but when I want to override Phaser.Group's update function, I had to do this; ElementalSpawner.prototype.update = function() { // Elemental Spawner update code here // super.update var i = this.children.length; while (i--) { this.children[i].update(); }};This works for sure, but I'm not comfortable with it. (So what if I was overriding a 200 line code function ) As you see I had to copy original group class's update functions contents into the overridden function. What I intended to do is similar to calling super.update() in AS3/Flash/Flixel. I'd like to ask for suggestions on how to extend and override functions of javascript/phaser classes? And more generally how would you design such structures like, spawners, healthbar renderers, GUI containers-updaters etc? I'm working on our "incomplete" LD48 game superdamage.com/LD29/dist Thanks.