• Content Count

  • Joined

  • Last visited

  1. A I figured this out after cracking open the source for the me.Container class. It turns out that the container's update method will update the absolute position of renderable child objects. With that, I was able to update my enemy laser to spawn with:"enemyLaser", theChild._absPos.x + game.EnemyLaser.width, theChild._absPos.y + game.EnemyLaser.height)); In addition, I moved this logic from the enemy update call into the enemy_manager's (aka - the container's) update call. The full change was: if (this.children.length > 0 && this.createdEnemies) { // pick a random child var childIndex = common.functions.getRandomInt(0,this.children.length -1); var theChild = this.getChildAt(childIndex); // pick a random number between 1 & 1000 var randomInt = common.functions.getRandomInt(1,1000); // still tweaking this to get the right amount of enemy fire if (randomInt > 900) {"enemyLaser", theChild._absPos.x + game.EnemyLaser.width, theChild._absPos.y + game.EnemyLaser.height)); } }
  2. First off - I'm having a lot of fun playing with melonJS. Great work on the library. I've just gone through the Space Invaders tutorial, and have worked through some of the challenges (for example, adding a HUD, adding waves). I'm now looking at adding enemy lasers that would be spawned from the enemy entities, and collide with the player. The obvious idea is that enemies should be able to shoot the player, and if the player is hit, then I'll decrement the number of lives. I've got the basic Enemy_Laser entity coded, and it appears to work, except for the initial position. When the player moves, and you hit the space bar, the player's Laser will fire from the player's current player position. The enemy laser, however, spawns from the initial position of the enemy entity objects rather than their current position. I suspect this is due to the enemy entities being wrapped within the enemy_manager container. Do I need to update the position of the enemy entities within the enemy_manager? I see there's a setChildsProperty() method in the container object. Can/should this be used to update the position of the enemy_manager child entities? You can view the source code here: