- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个使用 BitmapData.hitTest 运行的碰撞检测类。基本上,每次更新时,都会调用 .draw 方法,然后对两个 BitmapData 进行 hitTest 以查看是否存在碰撞。
它工作得很好,但是如果我开始旋转我用于 BitmapData 的源 MovieClip,转换不会在绘制方法中注册。所以我所做的是在 draw 方法中传递一个 Matrix。这样可行。但这是实际问题。如果我将 BitmapData 输出到舞台上的位图,我会看到位图是,事实上,它正在旋转,但现在它超出了 BitmapData 的边界(宽度和高度)。正在裁剪/剪裁源 MovieClip 的图像。
我的第一个猜测是旋转 BitmapData,但旋转似乎不可能。没有任何属性可以帮助您实现这一目标。还有别的办法吗?
更新:基本上,当 MovieClip 的位图克隆旋转到正坐标空间之外时,它不会被绘制。它在 BitmapData 设置的宽度和高度范围之外旋转。我可以将边界乘以 2,然后将位图置于设置边界内的中心,但原点永远不会固定,对象总是四处移动。效果很好,但无法将对象与任何特定点对齐。
这是我的独立测试代码。它要求您在舞台上有一个名为“iTest”的 MovieClip。我使用了一个相当垂直的箭头形状(高于它的宽度),这样我就可以在视觉上跟踪旋转并帮助强调剪裁问题:
var rotateTimer:Timer = new Timer(10);
function rotateObject_init():void
{
rotateTimer.addEventListener(TimerEvent.TIMER, rotateObject);
rotateTimer.start();
}
function rotateObject_stop():void
{
rotateTimer.removeEventListener(TimerEvent.TIMER, rotateObject);
rotateTimer.stop();
}
function rotateObject(_event:TimerEvent):void
{
// Deletes the previous bitmap
if (this.getChildByName("iTestClone") != null)
{
removeChild(this.getChildByName("iTestClone"));
testClone = null;
testData = null;
}
iTest.rotation += 1;
// Capture source BitmapData
var testData:BitmapData = new BitmapData(iTest.width, iTest.height, false, 0xFFFFFF);
// Capture source transformations
var testMatrix:Matrix = new Matrix();
testMatrix.scale(iTest.scaleX, iTest.scaleY);
testMatrix.rotate( iTest.rotation * (Math.PI / 180) );
testMatrix.translate(0, 0);
// Draw source with matrix
testData.draw(iTest, testMatrix);
// Output Bitmap
var testClone:Bitmap = new Bitmap(testData);
testClone.name = "iTestClone";
testClone.transform = testMatrix.tra
addChild(testClone);
// Always makes sure source is visible
this.swapChildren(iTest, testClone);
}
rotateObject_init();
最佳答案
好问题!
我试图制作一个旋转 10 度的正方形的 BitmapData 克隆。为了获得位图数据的旋转,我使用了克隆对象的矩阵。正如您提到的,问题是由于旋转枢轴而导致的偏移量。
这是我的样子:
为了解决这个问题,我虽然如果我得到 BitmapData 和最右边点之间的差异,那将给我 x 的偏移量,并对 y 执行类似的操作,将使我在正确的位置地方。
几乎,我看起来好多了(只有一两个像素似乎受到伤害):
好的,我觉得我明白了:)
那个偏移量是针对 x 的,但他误导的是,它是由边界矩形的 height 定义的,而不是 width .试试这个:
var box:Sprite = new Sprite();
box.graphics.lineStyle(0.1);
box.graphics.drawRect(0,0,150,100);
box.rotation = 10;
//get the size of the object rotated
var bounds:Rectangle = box.getBounds(this);
//make a bitmap data
var extra:int = 2;//cheating the trimmed pixels :)
var bitmapData:BitmapData = new BitmapData(bounds.width+extra,bounds.height+extra,false, 0x00009900);
//get the bottom left point
var bl:Point = getBottomLeft(box,bitmapData);
//get the matrix
var m:Matrix = box.transform.matrix;
//offset if
m.tx += Math.abs(bl.x);
//draw, using the offset, rotated matrix
bitmapData.draw(box,m);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = bitmap.y = 100;
addChild(bitmap);
function getBottomLeft(displayObject:DisplayObject,data:BitmapData):Point{
var radius:int = displayObject.getBounds(displayObject).height;
var angle:Number = displayObject.rotation * Math.PI / 180;
var angle90:Number = angle + Math.PI * .5;
return new Point(Math.cos(angle90) * radius, Math.sin(angle90) * radius);
}
您不需要在 BitmapData 构造函数中使用绿色背景,那是为了调试。此外,您只需要左下角的 x 位置,因此您需要返回一个数字而不是一个点。
所以稍微短一点的版本是:
var box:Sprite = new Sprite();
box.graphics.lineStyle(0.1);
box.graphics.drawRect(0,0,150,100);
box.rotation = 10;
var bounds:Rectangle = box.getBounds(this);
var extra:int = 2;//cheating the trimmed pixels :)
var bitmapData:BitmapData = new BitmapData(bounds.width+extra,bounds.height+extra,false, 0x00009900);
var m:Matrix = box.transform.matrix;
m.tx += Math.abs(getLeftmost(box,bitmapData));
bitmapData.draw(box,m);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = bitmap.y = 100;
addChild(bitmap);
function getLeftmost(displayObject:DisplayObject,data:BitmapData):Number{
var radius:int = displayObject.getBounds(displayObject).height;
var angle90:Number = displayObject.rotation * Math.PI / 180 + Math.PI * .5;
return Math.cos(angle90) * radius;
}
结果:
HTH,乔治
self 提醒:小心你想要的东西^_^
关于flash - 使用 draw 方法时如何旋转 BitmapData。宽度高度边界裁剪/裁剪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2165074/
Draw joust是什么游戏 Draw joust是一款voodoo推出的玩家对战类游戏,Draw joust游戏中文版叫做手绘战车游戏。 这次voodoo将该游戏的玩法再度升级,难度也有所提
我在本地托管了 draw.io,我们正在使用它来直观地表示仓库中托盘的位置。问题在于,当你在周围拖动托盘时,你经常会不小心调整它们的大小,这很痛苦。无论如何我可以禁用它或锁定托盘的大小吗? 最佳答案
我想在 draw.io 中格式化一个矩形,这样只有一个边框(左边框)是黑色的,其他边框:顶部、右侧和底部必须保持“清晰”。 我试图找出正确的编码来仅影响这些元素,但似乎您只能使用样式键影响整个边框:i
我的线正在连接,即使我没有将它们设置为多边形。 我的脚本基于 pyshp 包。 我的脚本如下所示: w=Shapefile.Writer() #shapetype 11 is a polylineZ
我在表单值中有一个标题(“cadeau check 50 €”),我想使用 arial.ttf 将其写入背景图像。我的文字是正确的,但对于欧元符号。我有 2 [] 到位。我不知道问题出在哪里。这是 P
我收到上述错误。我需要帮助修复它。我看过this question它似乎对我没有任何帮助,我在与需要它的指令相同的元素上拥有所需的指令。我也不明白为什么我的错误说无法找到指令“绘图”所需的 Contr
我正在使用 VBUC 将 VB6 应用程序迁移到 C#但我得到了这个错误: 无法将类型“System.Drawing.Image”转换为“System.Drawing.Icon”我的代码是:
我有一行代码是从某个地方借来的,Visual Studio 无法解决 Bitmap或 ImageConverter类引用。 我有: using System.Drawing; 代码行是 Image x
我正在尝试将花费很长时间的大型 Lucidchart 图转换为 Draw.io。 Draw.io 推荐 ctr-a、ctr-c、ctr-v,但这似乎不起作用。然而,Draw.io 也隐晦地提到: dr
我想显示一个相对较长的图表。我曾经使用过 javafx Canvas ,但有时会出现缓冲区溢出异常,因为绘制了很多值。我正在寻找一种不同的方法,并找到了一种使用 java.awt.graphics2d
我很困惑 System.Drawing.Image 和 System.Drawing.Bitmap 之间有什么不同 有人可以解释这两种类型之间的主要区别吗? 为什么要使用 System.Drawing
声明了一个位图 private Bitmap img1 = null; private Bitmap img2 = null; 从openFileDialog中选择图像后,图像将被放置。 选定的图
我想遍历 System.Drawing.Color 结构并使用它来初始化笔列表。 我是这样试的,但是字段类型不合适: colorList = new List(); foreach (
System.Drawing.Point 和 System.Drawing.PointF 有什么区别。你能举个这两者之间的例子吗? 提前致谢。 最佳答案 Point 使用整数坐标(int 代表 X 和
我正在为我们公司开发 WinForm 打印应用程序。 打印文档时,我需要获取文档上每个控件的System.Drawing.Color属性,并创建一个System.Drawing.Brush对象来画出来
我正在使用这个从另一个应用程序获取图标: Icon IEIcon = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
在 UIView 子类中,我覆盖了 Draw 子类以绘制一些自定义文本,但文本始终绘制为翻转文本。 这是我正在使用的代码: class TextViewProblem : UIView { publi
我想从 Zotero 导出的嵌套 XML/JSON(嵌套在子集合和集合中的单个项目)以编程方式生成 draw.io map 图。 我已经有了基本的 JSON/XML,可以适应 draw.io 的格式,
1) 重新绘制与绘制 这是一个哲学问题,但是...在不同分辨率下渲染游戏的“正确”或“可接受”的方式是什么(2d,我理解 OGL 视角如何工作...)?我应该为我的图像(如 Android APK)添
我是一名优秀的程序员,十分优秀!