简体   繁体   中英

Android Rotating a set of bitmaps around a common pivot point

I am trying to create a game like Jigsaw Puzzle. I am using a class that extends View and in its draw method, I am drawing different bitmap pieces. When user tap a bitmap, I rotates that bitmap by 90 degree angle. 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). to figure out its placement on the screen as bitmap objects in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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