metalNumb Posted December 17, 2014 Share Posted December 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
ultimatematchthree Posted January 13, 2015 Share Posted January 13, 2015 At least 2 possible solutions: 1) Change your group's classType property so that calling the create method creates your "smart object" instead of just a plain Phaser.Sprite. 2) Manually instantiate your "smart object" and add it to the group using the add method. Quote Link to comment Share on other sites More sharing options...
metalNumb Posted January 13, 2015 Author Share Posted January 13, 2015 Thanks for the reply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.