简体   繁体   中英

Scene change concept in JQuery Games

When my son, an early teen, was writing games with Pygame, I recalled I had to implement the scene-change code for him by myself.

Now he's using jQuery to write some simple games. Can anyone help us learn how to change scenes in jQuery games? The use case is like this:

In Scene 1, the blue team and the red team had a shootout. Say the blue team won with five team members left. These five must move onto a new scene. The new scene suggests a new background, the absence of all the red team, not even their dead bodies etc.

Do we have to do this at atomic, very low level?

Is there a high-level concept, API call etc., that we are missing?

Added:

In Pygame, scene2, scene3, scene44 etc are each a different file.

From scene1, I call scene2 like this:

sprites_to_live_on = sprite1, sprite2, soldiers_still_alive, ..    
background_for_scene2 = "/a/b/c/bkground123.png"    
scene2.start(sprites_to_live_on, background_for_scene2)

Each sprite carries over their power, health, weapons etc into the next scene automatically.

There is not really the notion of scene in gameQuery but there are some tools provided to help you achieve what you describe here. To Switch from one scene to another you would typically:

  1. pause the game with pauseGame (http://gamequeryjs.com/documentation/api/#pauseGame)
  2. display a splash screen to let the user know that the next scene is loading
  3. delete the sprites you don't need and add the new ones, create the new animations if you need any.
  4. resume the game with resumeGame (http://gamequeryjs.com/documentation/api/#resumeGame) You would typically passe a function to this call that will remove the splash screen once all new assets have been loaded.

You could separate the scene in different .js files and load them with jQuery.getScript (http://api.jquery.com/jQuery.getScript/). In the example above you would do it on step 3.

Keep in mind that most of the time your sprites and your game Objects are separate entity. For example you will have to remove the sprite of an enemy as well as "delete" the object implementing its behavior.

Hopes it helps, have fun coding your game with you son!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM