Jump to content

How call automatically world.create() from class that extends Sprite


sebamawa
 Share

Recommended Posts

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

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...};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...