3

I'm developing a game in Android and Java. In android I am using andengine for sprite image and i was able to rotate in all directions.

  int bikeFrame:
//bikeFrame++,bikeFrame--

bikeSprite.setRotation(bikeFrame);

I want to make the game in j2me also. But in j2me we have only four methods to rotate angle

(TRANS_MIRROR,TRANS_MIRROR 90,TRANS_MIRROR 270,TRANS_MIRROR 180)..

If i take images as frames I am still not getting smooth animation.

How to rotate sprite image in all angles in j2me?

tripleee
  • 175,061
  • 34
  • 275
  • 318
JohnRaja
  • 2,377
  • 6
  • 26
  • 47

2 Answers2

2

See this thread, omarhassan123 created a code snippet that should allow you to rotate the image by any angle you like.

There is a library called J2ME ARMY KNIFE that provides all sorts of image manipulation techniques, you can get it here.

Also, see this question: Image rotation algorithm

Another idea: decompile a game called Flexis Extreme. They do a lot of image rotation in real time so you could try to find out how they did it.

Community
  • 1
  • 1
JohnEye
  • 6,436
  • 4
  • 41
  • 67
  • Nokia sample does NOT "rotate image by arbitrary degree". It does use Sprite.TRANS constants to rotate. – Telmo Pimentel Mota Oct 04 '12 at 12:00
  • My bad, I thought that the "some values" meant that you can use any angle you like. I will fix the answer soon. – JohnEye Oct 04 '12 at 13:09
  • thanks... now i trying some examples with j2me army knife.. it's must be useful for my game development. j2me army knife will load in all devices? – JohnRaja Oct 05 '12 at 06:07
  • I don't know, but it should work on all devices unless it uses some special APIs. You can test that in emulator though. One thing that might happen is that you run out of memory because of extensive image manipulation, but that is something you would likely run into regardless of whether you use this particular library. See the live demo: http://www.j2mearmyknife.com/live-demo/ I find it quite amazing how much is possible with so little memory/CPU. – JohnEye Oct 05 '12 at 09:25
  • i tested J2ME ARMY KNIFE demo jar in samsung GT-c3222..its hanged.. other devices nokia and lg is working fine.. – JohnRaja Oct 05 '12 at 13:17
  • Nice to know. Can you identify what the problem is? The culprit could be one of the other cool effects so you could still use the library. – JohnEye Oct 05 '12 at 13:23
  • @JohnEye In omarhassan's code, the result image has the lot of redundant transparent rows and columns. How to fix tht ? – Vijay C Aug 07 '13 at 20:35
  • @Vijay C: Are you sure they're redundant? I think those could be there so that even an image that is rotated so that its diagonal is vertical or horizontal could fit. If this assumption is correct, you could modify the algorithm so that the lines are not there, but then you would have to recalculate the image's position each time you rotate it. Also, are you sure that they cause any problems in your setup? I'm sure you've heard it a thousand times, but premature optimization is a bad practice. – JohnEye Aug 08 '13 at 11:32
0

If you can, try LWUIT Image.rotate there is a sample at this page http://lwuit.blogspot.com.br/2008/11/round-round-infinite-progress-and.html

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22