Reload same level but retaining Player Object in libGdx.

huangapple go评论45阅读模式
英文:

Reload same level but retaining Player Object in libGdx

问题

我一直在为大学项目上的一款roguelite游戏使用libGdx进行开发。
基本想法是你有一个房间,清除敌人,当你使用门时,你会重新生成在同一级别,但敌人更强大。
问题是,我需要在重新加载级别时保留玩家的统计数据,而不会将其删除。

我一直在尝试研究场景,但我想知道是否有一种特定的方法可以重新加载渲染但保持玩家对象不变。

英文:

I've been working with libGdx for a University project on a roguelite game.
The basic idea is you have one room, clear the enemies, and when you use the door, you respawn in the same level, but with stronger enemies.
The thing is, i need to preserve the player stats for the course of the game without erasing it when i reload the level again.

I've been trying to look into Scenes, but was wondering is there is an specific way to basicaly reload the rending but leaving the player object untouched.

答案1

得分: 0

以下是翻译好的部分:

不太清楚,很大程度上取决于您如何构建/编写游戏。但一个简单的方法可能是确实有一个玩家类,其中包含一个图像(角色)和一个状态成员对象(或者您如何跟踪状态)。实例化一个玩家对象,并在游戏期间不断更新其状态,它们不会消失。

您的图像(Actor的子类 - 再次强调,是简化的),可以用于渲染玩家的可绘制物。如果您的级别始终相同,您可以使用相同的舞台来包含您级别的角色(玩家、敌人等)。您可以向舞台添加/删除角色,从而创建不同的级别。

但是您的玩家类不必离开。只有玩家的图像(Actor)可能会添加到/离开一个级别(舞台)。玩家类仍然将包含您需要了解的有关玩家的状态和任何其他属性。

英文:

Not a lot to go on, much would depend on how you've structured/coded your game. But a simplistic approach could be to indeed have a Player class, which contains say an Image (Actor) and a Stats member object (or however you keep track of stats). Instantiate one Player Object and keep updating its stats for the duration of your game, they won't go away.

Your Image (subclass of Actor - again, simplistic), could have your Player's drawable for rendering. If your level is always the same, you could use the same Stage to contain your level's Actors (players, enemies, whatever). You can add/remove Actors from the Stage, thus creating different levels.

But your Player class doesn't have to go anywhere. It is only the Player's Image (Actor) that might add/leave a level (Stage). The Player class would still contain the stats and any other attributes you need about your Player.

huangapple
  • 本文由 发表于 2023年6月15日 12:26:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定