I'm currently programming a game at the moment, and what I'm currently trying to do is replace multiple "objects" in the game by using a loop.

我目前正在编写游戏,我目前正在尝试通过循环替换游戏中的多个“对象”。

When I say "objects" I'm not referring to an object in OOP, but a simple entity in my game that is drawn on the buffer (example: a rock or a tree).

当我说“对象”时,我不是指OOP中的对象,而是在我的游戏中绘制在缓冲区上的简单实体(例如:岩石或树)。

Now this method of replacing objects works just fine if it's only a few objects, but if I'm trying to replace up to 25+ objects it looks a bit weird.

现在这种替换对象的方法可以正常工作,如果它只是几个对象,但如果我试图替换多达25个以上的对象,它看起来有点奇怪。

What I mean by that is you can see each object being replaced one at a time, rather than all at once. (I understand that this is because the task is executed in a loop)

我的意思是你可以看到每个对象一次被替换,而不是一次全部被替换。 (我知道这是因为任务是在循环中执行的)

This pretty much sums up what I'm doing, programmatically:

这几乎总结了我正在做的,以编程方式:

for(int i = 0; i < tilesToReplace; i++) //Looping through the total amount of tiles that will be replaced
//Spawning an object in the desired tile
spawnObject(objectPatch.objectId, //irrelevant, (new object ID)
        objectPatch.coords[0][i], //irrelevant, X Coordinate of the current index
        objectPatch.coords[1][i]); //irrelevant, Y Coordinate of the current index

I've already thought about doing something such as pausing the entity rendering until all of the objects I want to replace are initialized, but I'm wondering if there's a simpler way of doing this, such as a way of handling a loop that I'm not aware of. (I'm not really aiming for changes I can make with my object/rendering handling, etc.)

我已经考虑过做一些事情,例如暂停实体渲染,直到我想要替换的所有对象都被初始化,但我想知道是否有一种更简单的方法来做到这一点,比如一种处理循环的方法,我我不知道。 (我不是真的想用我的对象/渲染处理等进行更改)

2 个解决方案

#1


0

I tried this example with N = 10; replacing 100 labels still appeared simultaneous. The problem lay elsewhere in your program, and you're going to have to profile the code to see where. As a general principle, try to keep your activity on the event dispatch thread as short as possible; an sscce, for example, may be a useful exercise.

我尝试了这个例子,N = 10;替换100个标签仍然同时出现。问题出在您的程序的其他地方,您将不得不分析代码以查看位置。作为一般原则,尽量使事件调度线程上的活动尽可能短;例如,sscce可能是一项有用的练习。

更多相关文章

  1. JAVA-初步认识-第十章-对象的初始化过程
  2. java类与对象,用程序解释
  3. 孔维滢201771010110《面向对象程序设计(java)》第一周学习总结
  4. Xstream把xml转换成java对象的异常:java.lang.NoClassDefFoundErr
  5. java 和 JavaScript都可以在创建一个对象时,就可以通过这个对象调
  6. Java学习之面向对象三
  7. Javascript 事件对象(六)事件默认行为
  8. JAVA面向对象基础
  9. 使用js模仿java的实体类对类/对象进行get操作

随机推荐

  1. Android(安卓)和风天气SDK获取天气
  2. 2010.10.28———Android 02
  3. 【Android】FadingEdge
  4. 解读Android(安卓)3.2的新特性
  5. AndroidManifest.xml中一些权限配置
  6. Android NDK应用开发
  7. android和Myeclipse搭建环境
  8. 安卓设置文字自动滚动
  9. Cordova 3.x 源码分析(6) -- cordova.js本
  10. Android支持不同的密度或分辨率