Monday, October 3, 2011

Re: [android-developers] Efficient 2D Sprites

Hi,
 
You can start by splitting the image in more images
Usualy for this kind of games will be enough. So you can do some tests first, without spend to much time and see if the speed looks ok for you.
 
If the performance still remain poor you need to pass to the next step something like opengl
which is very simple for the 2D ... not so much work for you and the graphic proc. taking care about the speed you need
 
 
 
BR,
Gigi

On Sun, Oct 2, 2011 at 10:41 PM, Beck Olson <beckn8tor@gmail.com> wrote:
Greetings!

  I am working on porting a 2D java game to android. In our original
version we created png sprites that had each frame concatenated into a
single horizontal image. We are using drawBitmap to render each frame
sequentially. The performance is poor and according to the profiler
90% of the time is spent calling drawBitmap:

protected void render( Canvas canvas ) {
   Rect src = new Rect(this.currentFrame * this.frameWidth, 0,
(this.currentFrame + 1 ) * this.frameWidth, this.frameHeight );
   Rect dst = new Rect(this.position[0], this.position[1],
this.position[0] + this.frameWidth, this.position[1] +
this.frameWidth);
   canvas.drawBitmap(this.fullMap, src, dst, this.p);
}

Our images are 42x1344 and we are drawing about 12 sprites at a time.
The best frame rate we have been able to achieve is about 25 frames
per second (on a samsung galaxy).

So my question is what is the proper way to draw 2D sprites? Should we
split up each frame into its own image? Should we use Drawable objects
instead? Do we need to use OpenGL?

Any guidance would be greatly appreciated!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment