Deleting sprites that are off screen

Discussion and feedback on Construct 2

Post » Thu Mar 20, 2014 12:15 pm

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?
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Thu Mar 20, 2014 2:09 pm

There is a trigger:

Sprite -> Is Outside Layout
- Sprite Destroy
B
18
S
6
Posts: 348
Reputation: 2,633

Post » Thu Mar 20, 2014 2:31 pm

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)
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Thu Mar 20, 2014 2:34 pm

AllanR wrote: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
B
18
S
6
Posts: 348
Reputation: 2,633

Post » Thu Mar 20, 2014 4:50 pm

Code: Select all
Sprite is off screen
- Destroy

Will work fine

Code: Select all
Sprite.X < ViewportLeft - Sprite.width
- Destroy

To only destroy a sprite once it left through the left
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 21, 2014 1:27 am

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!
B
35
S
5
Posts: 411
Reputation: 3,406


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests