Many off-screen instances cause slow down

Discussion and feedback on Construct 2

Post » Wed Mar 06, 2013 2:26 pm

This might be an old question. so I want you guys give me a suggestion:)


So the situation is:
-My layout is farely big.
-There isn't too much on-screen objects but it can be about 400-500 instances in the whole layout.
-I tried use tiled-background as much as possible but for the graphic quality I can't reduce sprites anymore.
-I also have many invisible tiledbackground objects for cheaper collision.
-the averange FPS on ipad 1st gen is 20fps, iphone 3gs is 15 fps (with cocoonjs). it has no problem on PC.

so should I trying to cut my map into several layouts? or is there any way can help?
B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Wed Mar 06, 2013 4:48 pm

you may want to post your capx so we can see how to best help.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Wed Mar 06, 2013 7:03 pm

Are you using iOS 6? It's a lot faster.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Mar 06, 2013 7:06 pm

I found that happens with one of my games on the iPad2 and only the iPad2. I'm not sure what it is, but it might be related to objects bordering the layout.

I'm not sure exactly what the condition is, but with 400-500 objects something is forcing it to slow down.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Wed Mar 06, 2013 7:55 pm

The ipad 1 and iPhone 3GS are very under powered. Can they even run iOS 6? I seem to recall hearing that they can't, which means from my tests means you're getting about 33% less performance as a result compared to iOS 5. I don't know how many fps are possible to get out of those. You can check for what's causing the slowdown by backing up your project, then deactivating batches of code like the collision detection or making objects invisible and watching what it does to the frame rate. Common performance problems are caused by collision detection and overdraw (too many pixels being drawn per frame, a background with a sprite on top of it means those pixels get drawn twice).

You could run a test deleting objects in the layout, and if it helps, then splitting it into more layouts might be the way to go - or you could code it to dynamically create and delete instances based on their distance from the player, or you could bug rexrainbow to write a plugin to do that for you, since he's considering making one that does that already. :)

http://www.scirra.com/forum/forum_posts.asp?TID=62131&PID=395757&title=plugin-instance-bank#395757
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Wed Mar 06, 2013 10:21 pm

Thanks for lots of helping!
@BluePhaze: my capx is kinda of complex now and I used several custom plugin/behaviors in it so you might not able to open it:/ But I take some screenshot to explain it:

This is the layout. As you can see I have many sprites obj block out the level in stead of tiledbackground, because sprites have image point so I can use them to generate visual objects, and sprite can be scaled up so it will make some blur effect I need.




@Ashley : I have iphone 3gs on iOS 6, ipad on iOS5(6 is not supported )

@Arima : I tried your suggestion and set most objects to invisible, the framerate doesn't change too much, but a little more stable. Is there anyway to test on-screen overdraw? because I do have several overlay from foreground to background.(I even have a full-screen overlay for gradient effect)
And thanks for the suggested plugin, I will try it out:)

B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Wed Mar 06, 2013 11:05 pm

Well, the plugin doesn't exist yet, I meant that rexrainbow mentioned possibly making it. If you set pretty much everything to invisible and it didn't really affect fps, then rendering is likely not the problem. Go on to disabling parts of your code, like collision detection, and see what that does to the framerate.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Wed Mar 06, 2013 11:23 pm

It's a logic performance problem, every sprites with collisions more than 50 objects per layout in runtime COULD lag.

If there are 400-500 instances, the performance goes hell.

CocoonJS is a renderer performance, not logic performance, I hope Rexrainbow is making new plugin like auto-save/load instances outside a range, it's more like memory managment.
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Thu Mar 07, 2013 10:44 am

Thanks guys for the explain and help! I have tried disable all collision for object movement, such as pushout solid thing, it doesn't help. I also use the same event sheet in another empty map, it runs double the fps. so I guess it might still because of too many objects cant handled by 3GS's weak CPU.
But here is an idea: On the start of layout, can we remember all the instances location,rotation and other properties, save it into database, then destroy them when off-screen, and create them when on-screen? The InstancesBank seems can make it but I don't know how to spawn instances according to on/off-screen:/
B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Thu Mar 07, 2013 11:30 am

I am working on a level editor where the plan is save the canvas arrangement to an array and then save the array.
But I haven't gotten that far yet to show any code.

The problem with my code is that I will push to the array:
"For Each Instance Order By Instance.Zindex ascending"
so that when it put them all back, they would be in the correct Zorder.
You would have to sort by X maybe, or make an instance variable labeling which column they belong to, and you could draw that column offscreen as your character approaches.

--I have a game that checks the FPS every couple seconds, and if it's below 25 twice in a row, it starts "destroying" extra scenery.

Edit: to clarify the column idea, your character is touching a block that's instance variable says it is in column 5. So if column 2 and column 7 aren't drawn, draw them. (if headed right, column 2 would have been drawn already, and column 8 would get drawn.)
Then you would also destroy any Column 1 and column 9 instances.Paradox2013-03-07 12:13:30
B
200
S
51
G
30
Posts: 897
Reputation: 36,496

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Tom and 18 guests