简体   繁体   English

jQuery游戏中的场景更改概念

[英]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. 当我十几岁的儿子与Pygame一起写游戏时,我记得我必须自己为他实现场景转换代码。

Now he's using jQuery to write some simple games. 现在,他正在使用jQuery编写一些简单的游戏。 Can anyone help us learn how to change scenes in jQuery games? 谁能帮助我们学习如何在jQuery游戏中改变场景? The use case is like this: 用例是这样的:

In Scene 1, the blue team and the red team had a shootout. 在场景1中,蓝队和红队发生了枪战。 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? 是否缺少我们缺少的高级概念,API调用等?

Added: 添加:

In Pygame, scene2, scene3, scene44 etc are each a different file. 在Pygame中,scene2,scene3,scene44等都是不同的文件。

From scene1, I call scene2 like this: 从scene1中,我这样调用scene2:

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. gameQuery中实际上没有场景的概念,但是提供了一些工具来帮助您实现此处描述的内容。 To Switch from one scene to another you would typically: 要将场景从一个场景切换到另一个场景,通常需要:

  1. pause the game with pauseGame (http://gamequeryjs.com/documentation/api/#pauseGame) 使用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. 使用resumeGame(http://gamequeryjs.com/documentation/api/#resumeGame)恢复游戏通常,您将向此调用传递一个函数,该函数将在加载所有新资产后删除启动屏幕。

You could separate the scene in different .js files and load them with jQuery.getScript (http://api.jquery.com/jQuery.getScript/). 您可以将场景分为不同的.js文件,并使用jQuery.getScript(http://api.jquery.com/jQuery.getScript/)加载它们。 In the example above you would do it on step 3. 在上面的示例中,您将在步骤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! 希望能对您有所帮助,并与您的儿子一起编写游戏!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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