Deleting sprites that are off screen

0 favourites
  • 6 posts
From the Asset Store
Is a circular loading screen with code ready to use. No Animation.
  • So i have an infinite runner game where platofrms are spawned infinitely on the X and Y axis as the player runs/falls. I used to delete the platforms as the player ran along, but i just found out my delete script isnt working. Performance has been fine though. Our target platform is mobile, does that mean that I don't have to delete off screen objects past a certain point? Or am I missing something and maybe if I run far enough, performance will go down?

  • There is a trigger:

    Sprite -> Is Outside Layout

    • Sprite Destroy
  • I don't think off screen objects get rendered, so there is not much of a performance hit to have them around (but it is still having to loop through all of them every tick and calculate their position).

    If you delete all the ones off screen you may also be deleting new ones you are setting up to scroll onto the screen. So, you may want to do something like Sprite.X < -100 then sprite Destroy.

    (obviously you have to factor in the width of the platforms to make sure they are completely off the screen)

  • I don't think off screen objects get rendered, so there is not much of a performance hit to have them around (but it is still having to loop through all of them every tick and calculate their position).

    If you delete all the ones off screen you may also be deleting new ones you are setting up to scroll onto the screen. So, you may want to do something like Sprite.X < -100 then sprite Destroy.

    (obviously you have to factor in the width of the platforms to make sure they are completely off the screen)

    I believe this is not true. For "sprite is off screen -> destroy" I believe it just deletes that instance of sprite.

    Another workaround is create a boolean variable "onScreen" and once the sprites are set on screen, make that instance boolean to true, then once its off the screen check to make sure that the boolean is set to true before its destroyed.

    Kind of a workaround, to check to make sure that the platform has made its course of being on screen.

    ->Sprite is off screen

    ->Sprite OnScreen is set to True

    • destroy
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sprite is off screen
    [ul]
    	[li]Destroy[/code:3kjecbb3][/li]
    [/ul]Will work fine
    
    [code:3kjecbb3]Sprite.X < ViewportLeft - Sprite.width
    [ul]
    	[li]Destroy[/code:3kjecbb3][/li]
    [/ul]To only destroy a sprite once it left through the left
  • the only thing is, the player might have to backtrack, and on some levels they can get around the object chasing them to go left, so I would use

    Sprite.X < ViewportLeft - Sprite.width - 400

    • Destroy

    then switch it up for Y axis up and down, and X axis going right. thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)