1.定义firstspace.def
<root>
<Properties>
</Properties>
<ClientMethods>
</ClientMethods>
<!-- BaseApp上的远程方法 -->
<BaseMethods>
</BaseMethods>
<!-- CellApp上的远程方法 -->
<CellMethods>
</CellMethods>
</root>
2.entities.xml中添加
<firstspace></firstspace>
3.base部分加入firstspace.py
import KBEngine
from KBEDebug import *
class FirstSpace(KBEngine.Space):
"""
FirstSpace的base部分,
注意:它是一个实体,并不是真正的space,真正的space存在于cellapp的内存中,通过这个实体与之关联并操控space。
"""
def __init__(self):
KBEngine.Space.__init__(self)
# 存储在globalData中,方便获取
KBEngine.globalData["FirstSpace"] = self
4.cell部分加入firstspace.py
import KBEngine
from KBEDebug import *
class FirstSpace(KBEngine.Space):
"""
FirstSpace的cell部分。
"""
def __init__(self):
KBEngine.Space.__init__(self)
pass
5.account.py初始化的时候放入FirstSpace
# 客户端一旦连接,就把他放入FirstSpace空间
first_space = KBEngine.globalData["FirstSpace"]
self.createCellEntity(first_space.cell)
6.onBaseAppReady创建space
KBEngine.createEntityLocally("FirstSpace", {})
7.account销毁的时候销毁cell中的实体
def onClientDeath(self):
"""
KBEngine method.
客户端对应实体已经销毁
"""
if self.client is not None:
return
if self.cell is not None:
# 销毁cell实体
self.destroyCellEntity()
return
DEBUG_MSG("Account[%i].onClientDeath:" % self.id)
if not self.isDestroyed:
self.destroy()
以上内容参考了comblock官方文档https://www.comblockengine.com/docs/1.0/get-started/createscene/