简体   繁体   English

当精灵在视口之外时如何删除它们,但如果我返回它们的位置以保存 memory,然后再次添加它们

[英]How can I remove sprites when they are outside viewport, but then add them again if I return to their location to save memory

I'm creating an open-world RPG like Neverwinter nights.我正在创建一个开放世界的角色扮演游戏,比如无冬之夜。 But I'm worried about memory and am afraid if I just populate a huge world with physics-based sprite nodes, I won't have any memory for anything else.但我担心 memory 并且担心如果我只是用基于物理的精灵节点填充一个巨大的世界,我不会有任何 memory 用于其他任何事情。

To combat this, I want to remove the sprites when they go far outside of the viewport and then re-add those sprites when I get close to their location.为了解决这个问题,我想在精灵 go 远离视口时移除精灵,然后在靠近它们的位置时重新添加这些精灵。

How could I accomplish this?我怎么能做到这一点?

To any and all who take time to help me with this, thank you!感谢所有花时间帮助我的人,谢谢!

You can store all data on a database like CoreData with exact parameters you need like states and positions whatever do you need.您可以将所有数据存储在 CoreData 之类的数据库中,并带有您需要的确切参数,例如您需要的状态和位置。

Then you can create a method to get all objects on a specific position with radius and use this method when the player moves or when you need to check things like a quest on another site, take those objects and compare with current objects, place again on the correct site the new ones and remove the old ones (they are not on radius probably or disappears for another reason)然后,您可以创建一个方法来获取具有半径的特定 position 上的所有对象,并在玩家移动或需要检查其他站点上的任务等内容时使用此方法,获取这些对象并与当前对象进行比较,再次放置新站点的正确站点并删除旧站点(它们可能不在半径上或由于其他原因而消失)

This is a complex approach but it could work.这是一种复杂的方法,但它可以工作。

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

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