2d-bounding-box 中文文档教程

发布于 5年前 浏览 21 项目主页 更新于 3年前

simple 2d bounding box library

请注意,这仍处于 alpha 阶段,可能包含很多错误。 如果遇到错误,请提出问题。

使用它:

let BoundingBox = require('2d-bounding-box');

let bb_create = new BoundingBox( min_x, min_y, max_x, max_y, [origin_type]);

有时你已经有了一个具有特定宽度和高度的实体,你希望 无需根据此生物的尺寸创建边界框 自己计算正确的位置。

重要的是,对于这些计算,您定义了您的来源 实体是。 它是否位于决定位置的实体中间 或实体周围的任何地方,例如左下角。

let bb_from_entity = BoundingBox.create( origin_type, position_x, position_y, width, height);

对于原点类型,有 9 种可能的选项:

BoundingBox.ORIGIN_CENTER;
BoundingBox.ORIGIN_LEFT_BOTTOM;
BoundingBox.ORIGIN_RIGHT_BOTTOM;
BoundingBox.ORIGIN_CENTER_BOTTOM;
BoundingBox.ORIGIN_LEFT_CENTER;
BoundingBox.ORIGIN_LEFT_TOP;
BoundingBox.ORIGIN_CENTER_TOP;
BoundingBox.ORIGIN_RIGHT_TOP;
BoundingBox.ORIGIN_RIGHT_CENTER;

如果您需要更多选项,您必须自己计算偏移量,然后 通过 new BoundingBox(...) 方法实例化边界框。

请参阅演示目录中的 demobasicbb.html 文件以获取示例。

如果你想摆弄 demobasic.js 文件重新编译它 gulp less browserify 在刷新演示basic_bb.html 文件之前。

simple 2d bounding box library

Note, this is still in alpha and may contain lots and lots of bugs. Please make an issue if you encounter a bug.

To use it:

let BoundingBox = require('2d-bounding-box');

let bb_create = new BoundingBox( min_x, min_y, max_x, max_y, [origin_type]);

Sometimes you already have an entity with a certain width and height, and you wish to create a bounding box based on the dimensions of this creature without having to calculate the correct positions yourself.

Important is for these calculations that you define where the origin of your entity is. Is it smack in the middle of the entity that decides the position or anywhere around the entity, bottom left for example.

let bb_from_entity = BoundingBox.create( origin_type, position_x, position_y, width, height);

For the origin type there are 9 possible options:

BoundingBox.ORIGIN_CENTER;
BoundingBox.ORIGIN_LEFT_BOTTOM;
BoundingBox.ORIGIN_RIGHT_BOTTOM;
BoundingBox.ORIGIN_CENTER_BOTTOM;
BoundingBox.ORIGIN_LEFT_CENTER;
BoundingBox.ORIGIN_LEFT_TOP;
BoundingBox.ORIGIN_CENTER_TOP;
BoundingBox.ORIGIN_RIGHT_TOP;
BoundingBox.ORIGIN_RIGHT_CENTER;

If you need more options, you will have to calculate the offsets yourself and instantiate the bounding box via the new BoundingBox(...) method.

Please see the demobasicbb.html file in the demo directory for examples.

If you wish to fiddle with the demobasic.js file recompile it with gulp less browserify before refreshing the demobasic_bb.html file.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文