box2d-js元素与外部图像 [英] box2d-js element with external image

查看:141
本文介绍了box2d-js元素与外部图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,在不同的box2d js实现的示例中,我只能找到在形状(球/盒子等)中定义的元素,是否有办法创建由图像定义的元素,例如:一块巨石?

So far in the samples of varies box2d js implementation I can find only element defined in shapes (ball/box/etc), is there a way to create an element defined by an image, e.g. a boulder?

推荐答案

你可以使用 b2PolyDef b2PolyShape 用于创建多边形的对象。

You can use the b2PolyDef and b2PolyShape objects to create polygons.

本文档适用于AS3,但找出等效的JavaScript相对简单。

This documentation is meant for AS3 but it is relatively simple to figure out the JavaScript equivalent.

如果你想自动化从图像的边界框到多边形的映射,你可以使用canvas和 getImageData()来搜索寻找非透明的像素(假设您的图像具有透明背景)。这可能比它的价值更多。

If you wanted to automate the mapping from an image's bounding box to the polygon, you could use canvas and getImageData() to seek through the pixels looking for non transparent (assuming your image has a transparent background). This is probably more effort than it is worth though.

另见了解Box2D中的自定义多边形

这篇关于box2d-js元素与外部图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆