Game is still lagging!

Get help using Construct 2

Post » Wed Sep 02, 2015 6:58 pm

I made a fairly straightforward game and compiled it through cocoonjs. The Game Worked fine but had problem putting ads on using admob so decided to compile through Intel xdk. After downloading it through the Google play store I noticed that it lags a lot.

I made the following changes to try and solve the problem:

-changed all text to sprite font
-reduced collision points on the sprites to just 3
-changed webstorage to local storage for the highscore so that on start of layout it runs better.
-destroy sprites outside of layout
-changed properties to rounded pixels

Just to quickly explain the game. It consists of a player on the left side of the screen. 4 types of enemies are spawned every random 1.3,1.8 seconds. The enemies are in a family and randomly chosen when spawned. If the player destroys the enemy a point is gain if not then It's game over. Simple!

I would appreciate it massively if someone could help me out with what the issue may be.

Thank you
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Wed Sep 02, 2015 8:40 pm

I'm not sure about admob, but you can go through this list and see if any of it helps. It's something I borrowed from a thread to help me with my projects. It's pretty much a check list to help with efficiency. Just salvage what you can from it. I know the post was to someone else, but there might be something useful. Also someone else might be able to help better with your specific questions.

1.- for the red character: Use a container for the eyes
2.- for the red character: For the jump use image points or use EaseTween.
3.- For the whole project: use Powers of two in the sprites.
4.- Use PNG8 for the background
6. - Keep pixel rounding on.
7.- Don't play animations too often.
8. - Remove collision from backgroun images, and uncollidable objects.
9. - Pre-plan as much code as possible and use function object to cut back on events.

On code:
6.- Use delta time, you have lots of actions using time. That will help on frameratesss.
7.- Also, use Groups, your code needs it, a lot.
8.- And Functions, they can pass variables and data.
9.- And Families, you are using lots of single events for destroying any block. Example on how to fix this: Assign instance variable ID "destroyOnClick" to anything that you want to be destroyed on click, and create a Group for that.
10.- Why use WebGL if iOS doesn't support it?
11.- The code is ALL the time checking and updating the End Screen (just remove the forest background to see what I mean).
12.- Hide the End Screen btw., and only show it or create it when the red thing is over the Goal block.
B
7
S
2
Posts: 92
Reputation: 663

Post » Thu Sep 03, 2015 1:46 am

can you send me the link to the forum page this is from. Only because I cant understand some of it since it is out of context.

3: For the whole project: use Powers of two in the sprites?........what does it mean by that? 2,4,8,16? I'm confused

7: Don't play animations too often......all my enemies are an animation that are spawned every 1.3-1.8 seconds. could this be the issue?

On code:
6.- Use delta time, you have lots of actions using time. That will help on frameratesss.....when would i be using this?
7.- Also, use Groups, your code needs it, a lot.......what does this mean?
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Thu Sep 03, 2015 11:09 am

"can you send me the link to the forum page this is from. Only because I cant understand some of it since it is out of context."

Just to warn you it's an old post about an unhappy customer with the same kind of problem. Lag... BUT the users swear it's because of the persons own doing, and great things are made in construct... so likely he could have improved his code/image performance by following proper procedures.

good-scam_t82598?start=20

"3: For the whole project: use Powers of two in the sprites?........what does it mean by that? 2,4,8,16? I'm confused:

- Yes. Check out this article for more information. Sprites should be in boxes that are to the power of 2,

http://www.katsbits.com/tutorials/textu ... of-two.php

same with tiles and backgrounds. This article should help a lot with that.

https://www.scirra.com/blog/112/remembe ... our-memory

"7: Don't play animations too often......all my enemies are an animation that are spawned every 1.3-1.8 seconds. could this be the issue?"

I'm not sure about the depth of Construct and its capabilities. This would be a question best suited for another member. I would say to watch where you're spawning enemies though. If they don't need to be on the screen, maybe they shouldn't exist (that is if you spawn them off screen). Like spawn enemies a few px off screen before the player gets to them (to make sure your not spawning baddies the player can't see), destroy anything that falls through the floor or off screen... if you're using gravity only use it on objects that need it and are in player view. (except in important cases)

On code:
"6.- Use delta time, you have lots of actions using time. That will help on frameratesss.....when would i be using this?"

- Use delta time any time that you lerp, or move something.

Say you have an even press right key. and that event does player.X + 12 every tick. What you really want is player.X + 12 * dt. This will make your game framework independent. Without delta time your movements are set to frame, thus effected by processor speed. dt

Here's some knowledge for you on DT

https://www.scirra.com/tutorials/67/del ... dependence

7.- Also, use Groups, your code needs it, a lot.......what does this mean?

- I can't really help with families and groups, I'm still learning this. One thing I can warn you is that if you don't know how families work you'll get some bad behavior, so don't implement these unless you need them, and you know what they do. Backup your project and have a good copy before you make any major edits...

Sorry, I couldn't give more information, but if you read those articles it'll make your game better :)
B
7
S
2
Posts: 92
Reputation: 663

Post » Thu Sep 03, 2015 1:51 pm

Some really nice info on improving memory when exporting, I will be reading this through step by step shortly! Thanks!
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Thu Sep 03, 2015 1:58 pm

thanks @JeremyBenson11 i'll have a go.

for when i spawn the enemy should i change the every 1.2,1.8 seconds create enemy to dt time?

and also where i have every 5 seconds add 1 to global variable. should i also change that to dt?
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Fri Sep 04, 2015 2:39 pm

B
7
S
2
Posts: 92
Reputation: 663

Post » Fri Sep 04, 2015 5:56 pm

@JeremyBenson11 I read up on the DT it says that for things such as every x seconds you don't use dt. so I dont think dt is the issue.

I made the mistake of not testing my app as I went along. I'm really unsure what the problem is and have been suffering with the problem for several months now. I can always PM you capx if you're good with understanding C2?

I don't think it is due to the webstorage or local storage that I am using since everyone else uses it in their apps. Could it be the images I made for the sprites? they're only around 100x100px and i made them in adobe illustrator and just exported as a standard PNG and the image size isn't very large, much less than 1mb so i don't think that is the issue.

To be honest i'm honestly stuck with what it could be. I have no idea at all.
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Fri Sep 04, 2015 9:27 pm

Hm, I don't think I'd be able to help. I'm not a guru by far, and have my own questions really. What did you use for you images? For things like backgrounds and stuff you're not supposed to use sprites. There's tiled background and tiled map. Using too many objects can slow your game down.

The reason being is sprites have member data and functions attached to them. If you use these for something that's not going to use the functionality it's a waste of memory.

Have you heard of classes in programming languages?

well a sprite might store: image, position, angle, rotation, yad yad yad yad.. Then functions to rotate it, and everything else..

Where as an image object might just store a rectangle, texture, and vector for location.
B
7
S
2
Posts: 92
Reputation: 663

Post » Fri Sep 04, 2015 9:36 pm

Check this out for your image compression: https://www.scirra.com/tutorials/1154/d ... h-pngquant

Just wondering. You have a player that moves right? By keys, or buttons? That's where you want to use dt. If you don't your game will run different on different speed computers. That's what dt is for to set things to a second timer, rather than frame rate alone, which is run by cpu power.
B
7
S
2
Posts: 92
Reputation: 663

Next

Return to How do I....?

Who is online

Users browsing this forum: jasontoups and 1 guest