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 / What to include in/exclude from mainloop?

Author
Message
Danishly
9
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 19th Aug 2015 00:27
Hello again guys, I am starting to get the grips on things now.

But, what should be in the mainloop? And what should NOT be in the mainloop? I usually set display properties and load sprites and images before the mainloop. But as i start to write logic in the mainloop, i become a little confused. How do i handle multiple logics? I am making an app with several tabs.



What happens here is that I end up on the designated "tab", but how do i continue? Thank you so much for reading all this, and even more, helping

Just started - Much to learn
trietias
9
Years of Service
User Offline
Joined: 20th Jul 2015
Location:
Posted: 20th Aug 2015 04:20
I'm still new to AppGameKit and coding too, so I'm not sure how useful my advice would be, but I'll give it a go!

It sounds like you're trying to move on with the next part of your app, right? In this case, I would use game_states to let the program know what state the game should be in.

you could declare a variable (game_state for instance) and set conditions for when it is a certain number.

In this case, if that screen you had is the opening screen, you would do something like



I wasn't 100% sure what you would do for each of those tabs, but that's how I would do it -- except I would put that if condition inside a function and only hide the sprites instead of deleting them.

I hope that can help you a little bit!

Thanks!
Danishly
9
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 21st Aug 2015 00:14
Wow, thank you SO much for that answer, it's exactly what i was looking for!

I was not even aware of the select and case-commands That was super helpfull!

The if condition will end up as a function, yes so I can use it again without writing it all. And I took your advice of hiding the sprites
One question though, what does "global game_state=1" do?

Thank you so much!

Just started - Much to learn
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 22nd Aug 2015 22:50 Edited at: 22nd Aug 2015 23:03
You may check out this thread as there was a discussion about this topic.....http://forum.thegamecreators.com/?m=forum_view&t=213678&b=41

The way I went about setting up all my games follows Funnells advice...





This ^ was funnells advice to me when I had a similar situation, Hope it helps and you can read the above linked thread for more info. Many other people chimed in with diff ideas, Funnells is just what hit home with me.

Advice from my part: If your going to piece together some code so you can learn, don't copy and paste type it out yourself it will stick a lot faster. Even if you are rewriting a project, just go ahead and type it out. Sooner or later you wont even have to think, it will just be flowing out like the language you speak.

http://crazyprogrammerproductions.webs.com/
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 25th Aug 2015 23:28
Just to add to all this, the main principle I use is to never load or delete media in any loop that has player interaction. So my code may look like this (pseudo code so won't compile):



The above works well for apps that don't have a lot of media and will give the minimum time to transition between levels. If you have a lot of media then trying to load eveything in at once might slow the game down or at the very least take too long to load. So another way I do it is load only the media required for the current loop the program is in.



This free up memory but can cause pauses between going from the menu to the game loop and then between levels. You can refine this further by loading any media common to all levels - say for the HUD - before the main game loop and then delete it straight after the main game loop.

As for the thread Crazy Programmer I have no issue using multiple syncs for different loops. I find this makes it easier for dealing with multiple levels of sub menus. For instance the main menu may lead to something like an options menu - where the player can adjust some game settings - so the "options" sub menu would be contained in it's own function, with it's own loop with a sync at the end and some condition for exiting the loop and going back to the main menu - there's normally a "return to main menu" button. As the player moves between the different menu, the codes hides and shows the relevant labels, might even turn the collision off if I'm using sprites for buttons, and the player only interacts with the elements that are visible.

I found this to be easier to implement than having a single sync for the entire game, that's just my preference.

If you're getting really stuck then it might be a sensible idea to draw a simple flow chart that shows how things work, where the loops are and what the conditions are for exiting the loop and moving to the next state. This works for me.

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Danishly
9
Years of Service
User Offline
Joined: 10th Aug 2015
Location: Norway
Posted: 9th Sep 2015 14:26
Thank you so much guys, this has really helped me! I have had some problems in my loops with your method, with the screen flashing, but I have deleted almost all of my sync()'s, and now I am really starting to go somewhere

Just started - Much to learn

Login to post a reply

Server time is: 2024-11-21 15:05:45
Your offset time is: 2024-11-21 15:05:45