【问题标题】:How to access objects from specific layer in blender game engine如何在搅拌机游戏引擎中从特定图层访问对象
【发布时间】:2015-07-02 17:38:35
【问题描述】:

我想制作一款具有渐进式关卡生成的游戏。我在另一层有关卡的一些不同部分,我在第一层使用 python 控制器中的添加对象生成它们。

问题是当第一层中有多个对象都具有相同的名称时。然后,混合器不会访问另一层上的原始对象,而是在第一层的对象中生成。

如何访问对象

这里有一些代码

#import
import bge
from bge import logic

#define add
add = logic.getCurrentScene().addObject

#add object
add('objectName',' location',0)

【问题讨论】:

    标签: python game-engine blender


    【解决方案1】:

    如果你想直接访问一个对象,你可以创建一个列表并访问它:

    import bge 
    from random import random
    
    def main():
        cont = bge.logic.getCurrentController()
        own = cont.owner
        scene = bge.logic.getCurrentScene()
    
        #Your list
        objlist = [obj for obj in scene.objects]
        entity = objlist[obj]
        add = scene.addObject(obj,loc,0)
        add(entity,' location',0)
    

    或者直接调用对象:

    import bge 
    from random import random
    
    def main():
        cont = bge.logic.getCurrentController()
        own = cont.owner
        scene = bge.logic.getCurrentScene()
    
        #direct access
        entity = scene.objects['obj']
        add = scene.addObject(obj,loc,0)
        add(entity,' location',0)
    

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2019-12-22
      • 2013-01-17
      • 2015-05-13
      • 2013-06-27
      • 2015-01-26
      • 2017-11-20
      • 2011-07-22
      • 2015-04-23
      相关资源
      最近更新 更多