Jump to content

Creating a group of smart objects ?


metalNumb
 Share

Recommended Posts

Hey all !

 

So i've been trying to make my main.js file more compact by making a class for each of the game elements ( Player, moving platform,..) and now i want to do the same with my Enemies, only problem is that i used to generate dumb enemies at random locations and add them to a group in order to have group features ( like, killOutOfBounds ).

 

Something like this...

        var enemies ;        var enemyTimer;create:function(){        enemies = this.add.group();        enemies.enableBody = true;        enemies.physicsBodyType = Phaser.Physics.ARCADE;        enemies.setAll('outOfBoundsKill', true);        enemies.setAll('checkWorldBounds', true);..........function spawnEnemy (){var enemy = enemies.create(this.world.width - 50,                        Math.random() * (this.world.height/2), 'enemy'); }......enemy.body.velocity.x = Math.random()*(-speedMax+speedMin) - speedMin ;}enemyTimer = this.game.time.create(false);enemyTimer.loop(1000, spawnEnemy, this);

Now i want to do the same but the enemies generated needed to have some encapsulated AI in their own class.

i.e i want to make a group of OBJECTS not SPRITES.

 

How do i do that ?

 

Thanks.

Link to comment
Share on other sites

  • 4 weeks later...

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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