Search the Community
Showing results for tags 'sprite.call'.
-
Hello, recently I found code that is defining objects inheriting from Phaser.Sprite (if I google'd it and understood correctly). Can someone explain a little more about Phaser.Sprite.call() function? I haven't found it anywhere in docs. Also, what are the possible parameters? I found an example of code on some flappy bird tutorial : Pipe = function (game, x, y, speed) { Phaser.Sprite.call(this, game, x, y, "pipe"); game.physics.enable(this, Phaser.Physics.ARCADE, this); this.body.velocity.x = speed; this.giveScore = true; }; Pipe.prototype = Object.create(Phaser.Sprite.prototype); Pipe.prototype.constructor = Pipe; Pipe.prototype.update = function() { if(this.x+this.width<bird.x && this.giveScore){ score+=0.5; intro.prototype.updateScore(); this.giveScore = false; } if(this.x<-this.width){ this.destroy(); } }; I understand that "this" in the code is object (Pipe) right? I also have a question if I can (and how) create another sprite inside that Pipe - for example if I can have Pipe object that have two sprites (pipe1 and pipe2 which will have different properties). Or should I just define two objects and spawn both of them instead one with 2 sprites?
- 2 replies
-
- inheritance
- sprite.call
-
(and 2 more)
Tagged with: