beakartJs Posted August 29, 2019 Share Posted August 29, 2019 Hi! I'm working on a platform game and I have a question. If I have a map of sprites-objects in the game outside the field of view, should I deactivate these objects and activate them when they are seen? If so, what is the best, optimum way to deactivate sprites outside the drawing area? sprite.alpha = 0; and sprite.animations.stop (); ? Or other idea? I am trying (in the loop forEach for sprite vs player) something like this: // [...] main game loop // loop for sprite example exampleSprites.forEach(function(sprite){ if(player.position.x>sprite.position.x-game.width/1.5 && player.position.x<sprite.position.x+game.width/1.5 && player.position.y>sprite.position.y-game.height/1.5 && player.position.y<sprite.position.y+game.height/1.5) { if(!sprite.alpha) { sprite.alpha=1; sprite.animations.play('run'); } } else { if(sprite.alpha){ sprite.alpha=0; sprite.animations.stop(); } } }, this, true); Link to comment Share on other sites More sharing options...
icp Posted August 30, 2019 Share Posted August 30, 2019 This is the most efficient way: https://phaser.io/docs/2.3.0/Phaser.Sprite.html#visible You can read more about it here: Link to comment Share on other sites More sharing options...
Recommended Posts