Sign in to follow this  

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

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(){    ...}; 

Share this post

Link to post
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) {, game, x, y, 'bunny');    this.rotateSpeed = rotateSpeed;    // ... any other code you want...};

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.