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.

Author
Message
Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 24th Apr 2015 22:26 Edited at: 24th Apr 2015 23:00
Hi all.

Every game i attempt to make, at some point suffers with slow downs. It'll be fine at 60fps, then it'll drop rapidly to 30, and then slowly until things come to a crawl and the game crashes.

What are the main issues that could be causing FPS drops?

I realise you can't see my code, and there isn't much tbh, but i use a lot of functions. CreateBackDrop () would probably house loadimage, create sprite, set pos, depth, etc and then i'll call the function if lets say 'Start Game' Text was hit. Is this the right way to do things? I don't have much in the actual Main 'Do Loop' bar functions that house the majority of my code.

Edit; Incase this is the issue. I would have a function; Start Game for example, which would then house other functions that would load game controls and the like. Is this bad coding?

EDIT Final update - Oki, seems just running the programme, and leaving it as the start screen, with nothing loaded kills the frames until it crashes... Must be my system? It's a laptop i5, 2.5gz cpu, 8gig ram, intel Hd 3000 as the display. Windows 7. This shouldn't be a problem.

An example of the code:



function intro()
intro = createtext("Play")
SetTextPosition(intro, sW / 2, sH / 6)
settextsize(intro, 50)
SetTextAlignment(Intro, 1) // iMode - The aligment mode to use. 0=left, 1=center, 2=right
if GetTextHitTest(intro, GetPointerX(), GetPointerY()) and GetPointerPressed()=1

startGame()

endif
endfunction

function startGame()

SetViewOffset(sW,0)

backDropImg = LoadImage("land/forest.png")
bdSpr = createsprite(backDropImg)
SetSpriteSize(bdSpr, sW,sH)
FixSpriteToScreen(bdSpr, 1) //mode - 1=screen sprite, 0=world sprite

loadRobot()

endfunction

function loadRobot()
createsprite(1,pBotImg)
AddSpriteAnimationFrame (1,LoadImage("side view/robot_blueDrive1.png"))
AddSpriteAnimationFrame (1,LoadImage("side view/robot_blueDrive2.png"))
SetSpritePosition(1, sW + sW/4, sH - sH/2)
playsprite(1,10,1)
endfunction

Khadin
IronManhood
4
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 24th Apr 2015 23:10 Edited at: 24th Apr 2015 23:17
The way you are using LoadImage could possibly cause your games to slow down. If you call any function more than once, that contains:



then you are effectively loading that image more than once. Which is sort of a memory leak. It's likely that your game crashes from this. Although, it could be some different problem entirely.

What I mean is, don't do this unless you are only calling a function ONCE.



Instead, do this:

Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 24th Apr 2015 23:23 Edited at: 24th Apr 2015 23:25
Hey mate.

Yep, i tried moving all loadimages out of functions and not in the do loop. But that didn't help either I think it might be a laptop issue. Going to try the same code on my home comp later.

Thanks though.

EDIT; Wouldn't your initializeGame() have to be within the 'Do Loop' for it to load the images?

Khadin
Funnell7
7
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 24th Apr 2015 23:32 Edited at: 24th Apr 2015 23:37
It's hard to say as I can't see where your do and loop are, but my guess would be that you are creating sprites/text in a loop. For example all of your Create commands should not be in a loop... if you are happy to, attach your project then we can take a proper look...

EDIT:

Quote: "Wouldn't your initializeGame() have to be within the 'Do Loop' for it to load the images?"


You can have 'initualizeGame()' in the loop, but you must have a trigger to stop it from calling multiple times. For example;

if LoadGame = 1
initualizeGame()
LoadGame =0
endif

This ensures you only create the sprites/text once...

Using AppGameKit V2 Tier 1
Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 24th Apr 2015 23:38 Edited at: 24th Apr 2015 23:43
That's my do loop

do

intro()



controls()

debug()
Sync()
loop

Also unsure on the;

if LoadGame = 1
initualizeGame()
LoadGame =0
endif

Unsure how i'd end a function. If there's a command, i don't know it

I had ALL my loadimages above the do loop, so not with in. I then called createSprites within functions, and called them within the Do Loop. The above code is before i removed the loadimages from within the functions, but regardless, FPS still drops, and the app still stops working.

Khadin
Funnell7
7
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 24th Apr 2015 23:43
Right, so your intro() is being called every loop which is then creating your intro text every loop until your device runs out of ram... Not sure if you saw my edit above, but you need to have a check in place to stop you from calling the initialise routine multiple times... On my phone right now, so is difficult to provide an example. ..

Using AppGameKit V2 Tier 1
Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 24th Apr 2015 23:52
Hey Funnell7.

No idea how to stop calling a function. I assumed it ran the function once, then stopped lol.

Unsure what you mean by;

if LoadGame = 1
initualizeGame()
LoadGame =0
endif

I get the idea, but where did loadGame come from?

Khadin
Funnell7
7
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 24th Apr 2015 23:59 Edited at: 25th Apr 2015 00:00
If your function is in the loop then it will execute every time, not just once. LoadGame is a variable I created as a switch statement. Set it to 1 inirially, and your initializegame() function will run on the first pass, then set LoadGame to 0 and will not execute on any subsequent loops...

Using AppGameKit V2 Tier 1
IronManhood
4
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 25th Apr 2015 00:08
You can call all the functions you want before you enter the do loop. It is better coding to do that before the main loop so that you don't have to set up that check. Plus it is less confusing.
Funnell7
7
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 25th Apr 2015 00:17 Edited at: 25th Apr 2015 00:19
@IronManHood, sure, but what if you want to call the functions once you are in the loop? For example, I create my menus/scenes on the fly. I do not create everything upfront, I only create what I need as and when I need it, and delete what i dont. In my opinion, this is a lot cleaner and efficient.

Khadin, take a look at this post, this is how I set up my apps...

http://forum.thegamecreators.com/?m=forum_view&t=213678&b=41&msg=2551869#m2551869

Using AppGameKit V2 Tier 1
Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 25th Apr 2015 00:28
Oki guys, can't code right now, but i'll do as you say tomorrow, and report back Thanks for all the help.

Khadin
IronManhood
4
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 25th Apr 2015 00:55 Edited at: 25th Apr 2015 01:08
@Funnell7 You are correct. I was really only meaning for the images to be loaded once before the main loop. Then you don't have to worry about them and they won't be loaded again. How you structure your apps is essentially the same as how I structure mine. Each menu and even the game elements are created when they need to be used and deleted when not in use.

I have been working on this pong project for a while now. Rummage through it if you would like. You can learn or leave me feedback on mistakes or do nothing.

Attachments

Login to view attachments
Khadin
4
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 25th Apr 2015 17:56
Hey guys

Well, i've done what IronManhood has suggested, and it's working perfectly now Going to try what you've suggested now Funnell7 thanks guys, this was a major issue for me until now!

Khadin

Login to post a reply

Server time is: 2019-08-25 16:20:00
Your offset time is: 2019-08-25 16:20:00