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 / How to change scene or level?

Author
Message
Ninjadoodle
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location:
Posted: 25th Jul 2017 10:39 Edited at: 25th Jul 2017 11:05
Hi guys

I've just started playing with AGK2 and I can't seem to figure out how I would go about changing a scene/level.

Basically I would like to click a button and load a new level file (with a new level script)

All my levels are very different from each other, so this would be really for organisation.

Is there a way to do something like this?

Thank you in advance
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 25th Jul 2017 11:15
You'll need to devise a way doing that. I use the following;

Ninjadoodle
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location:
Posted: 25th Jul 2017 12:01
Hi @Supertino

Wow, that is very much over my head right now lol.

Thanks heaps for posting this, but do you know whether there is a simple example somewhere on how to switch between two files (just so I can try to understand what I'm doing).

Thanks you again!
bszaronos
6
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 25th Jul 2017 14:14
I am just starting to learn AppGameKit as well. This is what I came up with for my game. Probably not the most correct way to do this, but I like to keep it super simple

I created a some organization for my sprites.
1-408 screen sprites
409-420 items
421-460 lifts movable blocks
500-533 level image sprites

So sprites 1-408 make up my screen and play area. I make them all blank images. Sprites 409-460 are placed manually per level. I use sprites 500-533 as my ground, ladders, etc.
I then change the images 1-408 with sprites 409-533. This makes up my level.

My game main looks like this.

load all sprites
clear sprites 1-408
load level 1
load player
do
check player movement
if level 1 is complete
clear sprites 1-408
load level 2
loop

This way when I go to a new level, I just clear all the blocks and load in my new level.

Hope this helps

-Brian
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 25th Jul 2017 15:21
If you want to switch between multiple levels at will, the most important thing is to be able to unload your level just as easily as loading it.

Something like this might be what you're after (you can post this code into a blank AppGameKit project and run it, just add the 3 .txt codes to "1.txt", "2.txt" and "3.txt" in your media folder):

main.agc


1.txt


2.txt


3.txt


[in reality, you woudnt store level data in individual lines like this. You make a program to design them yourself in AppGameKit and export them to a file using writeInteger, then use ReadInteger to load them]

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
Ninjadoodle
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location:
Posted: 26th Jul 2017 00:01
Hi guys!

Thanks you heaps for your help here, I really appreciate it I'm sort of understanding the last example posted by @easter bunny

What I'm wondering is, whether you can load the entire level script + graphics etc.

I'm not just looking to load new layouts / maps, but instead a whole new minigame.

So basically - I'm playing mini game 1 and when its complete, I want to load mini game 2 which is in a completely new file.

Will the above allow me to do this?

Thank you again for all your help?
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 26th Jul 2017 13:05 Edited at: 26th Jul 2017 13:10
You can't load new game logic from a file (not in Tier 1 at least). To do what you want, you would have to use a separate game loop for each minigame. This requires structuring your entire project so as to support minigames. There are a few different ways to structure your project (such as the example posted by Supertino above). However I do it like this:

main.agc


minigame1.agc


minigame2.agc


menu.agc


Basically in your main.agc, you forever loop and call the next screen to go to (eg menu()).
Each of your screens (or minigames) contains 3 parts:
1. Loading code (where you load sprites/set variables)
2. Main loop (includes sync() and any game logic/handling input etc)
3. Closing code (where you delete all sprites/reset variables etc)
You set the variable gamestate to 0 in the loading code and exit the loop when it changes to something else (signifying that you want to change screens). Once the function ends, program flow will return to main.agc where the select game will check gamestate and direct you to the next screen (or exit the program).

I use this game structure for all my projects. It lets you easily jump around between screens/levels etc simply by modifying the variable [i]gamestate[i].

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
Ninjadoodle
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location:
Posted: 26th Jul 2017 23:17
Hi @easter bunny

Thank you, you rock! That is exactly what I was looking for - I just explained what I needed quite badly at first.

Again, I appreciate everyones help here - you guys are awesome

Login to post a reply

Server time is: 2024-04-26 20:39:27
Your offset time is: 2024-04-26 20:39:27