Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Trying to make a clicker game, the game slows down severly (i am talking like 8-10 FPS) slow when the numbers get even as high as 1000

Author
Message
Thugnificent
7
Years of Service
User Offline
Joined: 16th Aug 2016
Location:
Posted: 17th Aug 2016 13:03 Edited at: 17th Aug 2016 13:10
Hey guys, i am totally new to game making. I've been trying to make a game clicker one. So far i have the basics down and have prototype programmed the basics.

THe problem i am facing is as the numbers get a bit higher the FPS drops to a crawl. I think i am programming way too inefficiently. Is this an engine limitation and perhaps should i pick another language to code in altogether? Or is there any magical option i am missing in AppGameKit?

I am clicking on the main button and the counter increases by 1. I can litereally see a 10FPS drop when i get to 50 or higher count. This keeps on happening until the total FPS are dropeed down to below 10 FPS. THe CPU consumption of the application is also shooting through the roof.

My code can be seen below, i would highly appreciate any help.


Thugnificent
7
Years of Service
User Offline
Joined: 16th Aug 2016
Location:
Posted: 17th Aug 2016 13:26 Edited at: 17th Aug 2016 14:10
Ok did some google'ing around. Seems i have put the load images in the do loop and this sort of makes a memory leak.

Commenting out everything except the counter didn't make the FPS crawl after 50 clicks.

I think i have to load the sprites out of the do loop, anyone know an idea to load one sprite after a variable is at a certain number or above?


Can the above code be done without puttig it in the main Do Loop?

EDIT: Ok been messing around with the code. Had to put it inside the do loop, or perhaps a function. Seems like putting just the foo = 0 and foo = 1 made the do loop stop loading the sprites in every cycle. THis is pretty awesome man and very smart. Thanks!!!!!
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 17th Aug 2016 13:33 Edited at: 17th Aug 2016 13:37
you're right,

the lag is caused by the sprites being created over and over again in the main loop as soon as 'games' reaches the threshhold of 50.




Also, you may want to get rid of those gosubs and replace them with functions.
Rule #1: Gosub = Gosuck
Thugnificent
7
Years of Service
User Offline
Joined: 16th Aug 2016
Location:
Posted: 17th Aug 2016 14:07
Thank you so much Psy. I am just starting out in programming and i really really appreciate you guys' help. You guys are pretty awesome.

Back to program, i put the above code outside the Do Loop and it doesn't work. The sprite does not appear.

Also what is foo?

Secondly how can i use functions in this language? just simply define functions as



and to call the function is it same as other languages.



PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 17th Aug 2016 14:29 Edited at: 17th Aug 2016 14:38
foo is just a variable holding a value which is set to 1 once a condition is reached.

when the sprite is created for the first time, foo is set to 1 to ensure the sprite will not be created again.

If you are using the same variable in multiple functions, you either have to declare the variable as global or pass it to a function with functionname(variable1, variable2...)

I improved the code, should work now:



(edit) fixed a bug
Thugnificent
7
Years of Service
User Offline
Joined: 16th Aug 2016
Location:
Posted: 17th Aug 2016 14:46
OMG Thank you so much!!!!!!! You're the best!

Awesome, it works like a charm and no slow downs. I got to learn a lot from you bro, much appreciated!

PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 17th Aug 2016 14:47 Edited at: 17th Aug 2016 15:14
Don't mention it, you're welcome

(edit)
is not necessary, as you check for the mouse click anyway

damothegreat
User Banned
Posted: 14th Oct 2016 17:33
Hello

In your main loop - you have a gosub to autoclicker - inside this function - you have a createsprite.

"CreateSprite" in the main loop will eventually cause a hog of the PC

My best advise, is to declare all createsprites outside the main game loop

Damian

Login to post a reply

Server time is: 2024-04-20 11:55:40
Your offset time is: 2024-04-20 11:55:40