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 / help setting sprite image based on lvl number

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 21st Aug 2022 16:48
i have 4 images i have set to load based on a lvl number (barrier.lvl1,barrier.lvl2,barrier.lvl3......etc) instead of an if level number = 1 load blah blah image i would like to do something like this


barrier.maxlvl being the current lvl number that would match the barrie.lvl number 1-4. i think its possible im just unsure how to "word" it in code
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 21st Aug 2022 17:13
You could just put the image filename in the level file and parse it when the level loads. Another way would be something like naming each level as Level_1.dat, Level_2.dat, etc, and name the images as Level_1.png, Level_1.png and the rest should be easy. I've used both of those methods over the years.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 21st Aug 2022 17:33
I'll hammer something together for you shortly.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 21st Aug 2022 18:06 Edited at: 21st Aug 2022 18:10
I think this should suit your needs, download the attachment below, I'm guessing you already know how to use OpenToRead for loading your level data.

Attachments

Login to view attachments
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 21st Aug 2022 23:48
thank you for the help. im still learning the in and outs of loading and saving data. currently i have 5 scenes i swap between when increasing levels. i have everything for each level saved under a functioned, loadlevel1() loadlevel2() etc.. im thinking this is ok for what i have but if i had a lot of different levels it probably would be better to save under a data file?
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 22nd Aug 2022 04:11 Edited at: 22nd Aug 2022 05:42
Here's a basic level parser that I've just done for you to use, it gets the image filename from each level file each time you press Space, it does a few other things too like set some text and define its size and position.
It should be easy to add your own stuff once you've studied the code.

Download the attachment below, I hope this helps.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-23 08:32:29
Your offset time is: 2024-04-23 08:32:29