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.

AppGameKit Studio Chat / deleting and hiding sprites

Author
Message
Chrissell
10
Years of Service
User Offline
Joined: 2nd Apr 2013
Location:
Posted: 5th Apr 2021 17:18
Hi,
Im just about to try and read up on this subject deleting and hiding sprites.

Im trying to write my first game/app. most of the game is running fine that ive written so far. But what happens when playing the game you run out of lives and have to jump back to the beginning of the game/code.
If the program written creates the sprites again it results in an error message.

Is there an easy way around this?

I tried hiding the sprites so the splash screen re-shows at the begiinning. which works but the first screen wont display after?

Just wondering if anyone else has come accross this problem?

Many Thanks
Chris
C.R.Sellen
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 5th Apr 2021 22:23 Edited at: 5th Apr 2021 22:25
Yes, I have encountered this problem in the past when I first start making games. It's not really about whether hiding or deleting sprite (in any media) is better. It's about getting a full understanding of the structure of the game code.

The error you're seeing is probably the fact that when the code goes round it's loop for the second time it's trying to create a sprite (or assign a sprite ID) that already exists from the first time the code was run.

Chances are that you're code is doing something like this:

1: Load media - splash screen, game sprites, sound effects and so on

2: Hide game sprite

3: Show splash screen

4: Press play game

5: Hide splash screen

6: Show game sprites

7: Play game loop

8: Player dies

9: Show game over

10: Go back to step 1

Where as what you need is:

1: Load media - splash screen, game sprites, sound effects and so on

2: Hide game sprite

3: Show splash screen

4: Press play game

5: Hide splash screen

6: Show game sprites

7: Play game loop

8: Player dies

9: Show game over screen

10: Go back to step 2

The difference here is that the code never returns to step 1, media is only loaded once.

It may be that the splash screen is large and uses too much resources so instead of loading it in step 1, it's loaded at step 3 and deleted in step 5.

The best way to sort this out is to create a flow diagram that shows the overall structure of the game. The level of detail you go into depends on how well you already understand the structure. For instance, in the ten step example I didn't detail when the media for the "game over" screen is loaded. It can be loaded in step 1 and then hidden. It can be loaded between step 8 and 9 and then deleted before step 10, for instance.

I don't believe there's a correct answers as to when to delete sprites (or other media) or to hide them. It sometimes depend on how much media you need to load. If there's not much then loading it all at once can make your code tidier. However, if there's a lot of media then you may want to only load what the game needs at that particular stage, whether it's a menu at the start of the game or the sprites required for the level that's going to be played next.
Chrissell
10
Years of Service
User Offline
Joined: 2nd Apr 2013
Location:
Posted: 6th Apr 2021 09:22
Thanks for the help.

I see ,load media in the first step but don't return to that stage and hide all game sprites until they are needed.

I will give that a try.

C.R.Sellen
Chrissell
10
Years of Service
User Offline
Joined: 2nd Apr 2013
Location:
Posted: 6th Apr 2021 10:37
Yes I just tried it using your sequence and it works a treat.

Thanks for the help
C.R.Sellen
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 6th Apr 2021 20:16
That was easy

Login to post a reply

Server time is: 2024-03-29 09:49:10
Your offset time is: 2024-03-29 09:49:10