ageibert Posted November 19, 2014 Share Posted November 19, 2014 There are many phaser examples out there which are procedural or made from the templates, using only one Game.js file in which all objects/collision detections/settings aso. are handled. My questions is:Does anyone know about "real OOP" examples in which all game objects are classes? Eurico 1 Link to comment Share on other sites More sharing options...
spencerTL Posted November 20, 2014 Share Posted November 20, 2014 The examples give some ideas of extending groups etc. The templates show how to break a game down into states. I was a fan of AS3 and its classes but by learning from these I got a decent approximation of it. Much better than I expected from js anyway. Link to comment Share on other sites More sharing options...
sebamawa Posted November 20, 2014 Share Posted November 20, 2014 Hello, good point, Here, in the examples of Phaser: http://examples.phaser.io/ Examples 'extended sprite demo 1' and 'extended sprite demo 2' (in Sprite section) can guide you. For example ('extended sprite demo 1'):// Here is a custom game object (constructor)MonsterBunny = function (game, x, y, rotateSpeed) {Phaser.Sprite.call(this, game, x, y, 'bunny');this.rotateSpeed = rotateSpeed;};MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);MonsterBunny.prototype.constructor = MonsterBunny;/*** Automatically called by World.update*/MonsterBunny.prototype.update = function() {this.angle += this.rotateSpeed;};You can initialize the attributes of the 'class' in the constructor, and place the corresponding actions in the function update (), also add the methods you need. All this in a javascript file (here is your 'class' js), then from another file you can instantiate an object MonsterBunny with: var mb = new MonsterBunny(game, x, y, z); (for example), and use this object in the World.update() function. Eurico and totallybueno 2 Link to comment Share on other sites More sharing options...
dss Posted November 20, 2014 Share Posted November 20, 2014 I was thinking about writing tutorial on using ds.oop with phaser. Link to comment Share on other sites More sharing options...
ageibert Posted November 20, 2014 Author Share Posted November 20, 2014 Hi sebamawa,thank you very much for this answer. This and this article helped a lot and i got it to work. Link to comment Share on other sites More sharing options...
Recommended Posts