> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/bian-cheng-mo-shi/game-objects.md).

# 游戏对象

使用游戏对象模式，让你的代码更易读、更易扩展。

随着你的场景变得更加复杂，将其中一些逻辑放到独立的游戏对象文件中会很有用。这样做可以让场景的主要代码保持干净且易于阅读，同时将控制场景中多个实体的可复用部分封装起来。

游戏对象包含你在场景中可能遇到的某一类实体的所有属性和方法，例如一扇门、一个按钮或一个怪物。得益于这种抽象，包含场景主要逻辑的文件只需一行代码就能实例化完整的游戏对象。你也可以同样轻松地调用这些对象上的方法。

我们建议将每个游戏对象的定义放在单独的文件中。

## 类型对象模式

如果你的场景使用了多种有许多共同点的游戏对象类型，你也许会想进一步进行这一步重构，并定义一个 *base* 包含这些对象共同之处的游戏对象类型。然后，你可以创建继承自这个基类的子类。

你可以在以下内容中进一步了解这种模式： [《游戏编程模式》](http://www.gameprogrammingpatterns.com/type-object.html).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/bian-cheng-mo-shi/game-objects.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
