Search the Community
Showing results for tags 'extends'.
-
Hi, I've checked a couple posts on this forum regarding extending classes in Phaser, but get confused on how it exactly works, below is the code I'm trying to implement to add stats to a sprite: class spriteStats extends Phaser.GameObjects.Sprite { constructor (scene, x, y,myExtra) { super(scene, x, y); this.setTexture('../assets/testsprite.png'); this.setPosition(x, y); } setStats(speed, jump){ var stats = { "speed": speed, "jump": jump, } } getStats(){ return stats } } But when I attempt to create the sprite: var hero = this.add.spriteStats(100, 450, 'hero',0).setInteractive(); hero.setStats(5,5); it gives me a: "Uncaught TypeError: this.add.spriteStats is not a function". I don't think I'm extending the class correctly. Please forgive me, as I'm still relatively new to JavaScript. Thanks!
-
Hello everyone What is the most powerful and performance way to extends a PIXI class? Example from my side, I need the native PIXI.Container class but with more methods and properties, and here's how i proceed. PIXI.ContainerData = (function () { class ContainerData extends PIXI.Container { constructor() { super(); this.Sprites = {}; // others custom proprety for game obj }; get d() { return this.Sprites.d }; // return diffuse sprites get n() { return this.Sprites.n }; // return normals sprites //TODO: spine normal are arrays }; ContainerData.prototype.createJson = function(dataValues) { }; ContainerData.prototype.asignJson = function(dataValues) { }; //END return ContainerData; })(); I also know another way to extends functional prototyping. example: function ContainerData() { PIXI.Container.call(this); this.initialize(); }; ContainerData.prototype = Object.create(PIXI.Container.prototype); ContainerData.prototype.constructor = ContainerData; ContainerData.prototype.initialize = function () { this.Sprites = {}; }; I wondering about the cleanest and most efficient techniques to properly extend a class pixi? But especially on the most optimal way, knowing that JS need scan all the prototypes from the bottom to the top! The first technique worries me a little because in my console, Is look like that all the prototypes are cloned by reference and duplicate! So, i am interested in different techniques and advice. I am therefore looking for the most equitable approach between performance (speed) but also the readability for debugging. Thanks in advance.
- 4 replies
-
- container
- performance
-
(and 2 more)
Tagged with:
-
Hello, I am new to Phaser and I am trying to get a player extends from a sprite and display it in the screen but I am not being able and I don't know why. If anyone could help me It would be appreciated. Thank you. this is my code play.js player.js game.js
-
I can extends DisplayObject. But why can't I extends EventEmitter?
-
Hi friends! Definitely, the best way to work with collections of objects (enemies, obstacles, etc) is extend the Sprite class and to work with Groups (at least for me). In the examples on extending the Sprite class, we have: /** * Automatically called by World.update */MonsterBunny.prototype.update = function() { this.angle += this.rotateSpeed;};I can automatically call World.create function as above? to initialize the behavior of objects, and not make the call explicit to create function. Thanks, and excuse me for my english This, not work: MonsterBunny.prototype.create = function(){ ...};