sebamawa Posted November 18, 2014 Share Posted November 18, 2014 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(){ ...}; Link to comment Share on other sites More sharing options...
lewster32 Posted November 18, 2014 Share Posted November 18, 2014 Any code you want executed at the creation of the object is done in the constructor:// This is the 'constructor' of the MonsterBunny object - anything in this function is// executed when the object is created.MonsterBunny = function (game, x, y, rotateSpeed) { Phaser.Sprite.call(this, game, x, y, 'bunny'); this.rotateSpeed = rotateSpeed; // ... any other code you want...}; sebamawa 1 Link to comment Share on other sites More sharing options...
sebamawa Posted November 18, 2014 Author Share Posted November 18, 2014 Any code you want executed at the creation of the object is done in the constructor: Evident my friend lewster32, thanks Link to comment Share on other sites More sharing options...
Recommended Posts