jagd Posted March 3, 2015 Share Posted March 3, 2015 I'm creating a game with a very large world which will all be loaded from the beginning of the game. However, to cut down on resource use, I want to make it so objects will only do stuff if they are in the player's view. For example, an object that spawns a rockslide will only do so if it is within the player's view--or 'on-screen' if you want to use that term. How do I do this? Is there a way to say something like, if(Object.isOnScreen){ >>>do stuff} and would that work? Or for example, if it is offscreen, delete it. Link to comment Share on other sites More sharing options...
blizzardmuffin Posted March 4, 2015 Share Posted March 4, 2015 Sprites have a onOutOfBounds function which will call a function if the sprite were to go out of the world's bounds.sprite.events.onOutOfBounds(this.outOfBoundsFunction, this);outOfBoundsFunction: function() { >> do stuff}Not sure if that's what you're looking for though. Link to comment Share on other sites More sharing options...
GourmetGorilla Posted May 9, 2015 Share Posted May 9, 2015 When I try that I get an error on my first line of code below: alien.events.onOutOfBounds is not a function.alien.events.onOutOfBounds(this.outOfBoundsFunc, this);OutOfBoundsFunc = function() { ... do stuff};'alien' is the sprite, 'aliens' is the group, if I change the first line to 'aliens' I get the error: aliens.events is undefinedWhat am I doing wrong? Link to comment Share on other sites More sharing options...
GourmetGorilla Posted May 11, 2015 Share Posted May 11, 2015 hmmm... maybe because this is a sprite in a group, it needs to be written differently, so it knows it's talking about the sprite in the group?sprite.events.onOutOfBounds(this.outOfBoundsFunc, this);OutOfBoundsFunc = function() { ... do stuff};the sprite is 'alien' in a group called 'aliens'. How do I apply the above in this case? Link to comment Share on other sites More sharing options...
GourmetGorilla Posted May 11, 2015 Share Posted May 11, 2015 I fixed it alien.checkWorldBounds = true; alien.events.onOutOfBounds.add(alienOut, this); Link to comment Share on other sites More sharing options...
Recommended Posts