简体   繁体   English

Android 围绕公共枢轴点旋转一组位图

[英]Android Rotating a set of bitmaps around a common pivot point

I am trying to create a game like Jigsaw Puzzle.我正在尝试创建一个像 Jigsaw Puzzle 这样的游戏。 I am using a class that extends View and in its draw method, I am drawing different bitmap pieces.我正在使用一个扩展 View 的类,在它的 draw 方法中,我正在绘制不同的位图片段。 When user tap a bitmap, I rotates that bitmap by 90 degree angle.当用户点击位图时,我将该位图旋转 90 度角。 Its working perfectly.它的工作完美。 But user combines some bitmap pieces and then rotate the group, the bitmaps rotate around their center point destroying the group structure.但是用户组合一些位图块然后旋转组,位图围绕其中心点旋转,破坏了组结构。

My question is how to rotate a set of bitmaps around a common pivot point so that when a group of bitmaps rotate, it retains its shape structure?我的问题是如何围绕公共枢轴点旋转一组位图,以便当一组位图旋转时,它保留其形状结构?

I am assuming that you have each of the pieces center-weighted which is causing your problem.我假设您将每个部分都放在中心位置,这会导致您的问题。

On possibility is to have the background be a center weighted object or to look at background and declare the center as the point of rotation.一种可能性是让背景成为中心加权对象,或者查看背景并将中心声明为旋转点。

Then, calculate the approximate box size of each jigsaw piece (this could be dynamic based on if you are using Zoom).然后,计算每个拼图块的近似框大小(根据您是否使用 Zoom,这可能是动态的)。 to figure out its placement on the screen as bitmap objects in Draw().找出它在屏幕上的位置作为 Draw() 中的位图对象。

Now, imagine a line being draw from the center to the edge of the screen being rotated to get your angle.现在,想象一条从屏幕中心到边缘的线被旋转以获得您的角度。

So, based on this new information, you would need to calculate your new angle for each center weighted object (jigsaw piece) based off of the angle set by the center of the screen rotation.因此,根据这些新信息,您需要根据屏幕旋转中心设置的角度来计算每个中心加权对象(拼图)的新角度。 Each piece would have a different angle of rotation on its axis because of the new line or angle of rotation set by the center of the screen.由于屏幕中心设置了新的线或旋转角度,因此每个部分都将在其轴上具有不同的旋转角度。

This is more of an algorithm/calculation than programming, more specifics on your issue would help.这更像是一种算法/计算而不是编程,关于您的问题的更多细节会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM