| Reply | « Previous Thread | Next Thread » |
|
Hi,
so now I have done my homework and coded this cool sprite engine, which uses drawPixels for fast blitting, has all sprites in a width-aligned array and uses a modulo of 0 for blitting (hi to all old-school amiga coders out there!) i.e. scanlength=width. Now I can linearly copy a sprite from this array and apply e.g. a mask to it. However, I see two possibilities to do fast sprite masking: 1. use System.arraycopy first ro read a sprite into the buffer and the apply the mask to the values in the buffer 2. write an own loop doing the copying and masking . Assuming that 'spritefxbuf' is a static buffer for storing the affected sprites, the fist alternative looks something like this (simplified): int i, j; int off = sprites[s.frame]; int fxoff = 0; short[] buf = (short[]) spriteGfxSets[s.set]; System.arraycopy(buf, off, spritefxbuf, fxoff, s.w * s.h); for (i = w*h-1; i >= 0; --i) spritefxbuf[fxoff++] &= mask; bdg.drawPixels(spritefxbuf, true, 0, w, s.x, s.y, w, h, s.manip, NATIVE_SCREEN_FORMAT); The second one would be: int off = sprites[s.frame]; int fxoff = 0; short[] buf = (short[]) spriteGfxSets[s.set]; for (i = w*h-1; i >= 0; --i) spritefxbuf[fxoff++] = (short)((buf[off++])&mask); bdg.drawPixels(spritefxbuf, true, 0, w, s.x, s.y, w, h, s.manip, NATIVE_SCREEN_FORMAT); The big question now is: Whats faster??? I know there are some really good game coders out there with a lot of tricks in their sleeves :) (Hi Albech: your thread about sprite collisions really should have deserved you a beer ... I'll promise to get you one if I ever meet you). Any other tricks known for doing e.g. fast sprite zooming? (come on albech ... just one more trick) all the best Martin |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|