Note that there are some explanatory texts on larger screens.

plurals
  1. PORotate a bitmap in android about a point without animation of view
    primarykey
    data
    text
    <p>I found some good resources for rotating a bitmap in android here and elsewher eon the net. I am close to getting my code to work but apparently I don't fully understand how the Matrix Translations work. The following is three main functions from my sprite class. THey worked great before I added things to facilitate the matrix rotation (namely in the onDraw I called the draw with just x,y and no matrix). I wrote some test code to add a sprite, and rotate it from 0 to 360 and back to 0 again repeatedly. It results it in rotating about like its orbiting some odd point. In reality I want it to just sit there and spin:</p> <pre><code>public void Rotate_Sprite(int transform, int deg) { int spriteCenterX = x+(width/2); int spriteCenterY = y+(height/2); mMatrix.setRotate(deg, spriteCenterX, spriteCenterY); } public void Draw_Sprite(Canvas c) { //c.drawBitmap(images[curr_frame], x, y, null); //this worked great esp in move sprite c.drawBitmap(images[curr_frame], mMatrix, null); } public void Create_Sprite(blah blah) { ... ... mMatrix = new Matrix(); mMatrix.reset(); } public int Move_Sprite() { //with the matrix stuff, I assume I need a translate. But it does't work right //for me at all. int lastx=this.x; int lasty=this.y; this.x+=this.vx; this.y+=this.vy; mMatrix.postTranslate(lastX-x,lastY-y); //doesn't work at all } </code></pre> <p>I did find this <a href="https://stackoverflow.com/questions/1478849/j2me-like-sprite-on-android"> J2me like reference here.</a> Though it seems to have all my sprites I call rotate on in orbit around one point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload