×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    10

    Sprites on J2ME (again)

    Thanks for all your answers on my previous sprite queries, but I have another...

    I have built my own little sprite class, and it works pretty nice, however, when I move it, it leaves a trail behind itself, which doesn't suprise me, as I haven't done anything to counter it.

    My question is, what is the fastest way to redraw my background after the sprite has left that particular area. My background is an image from a PNG, so just redrawing a white rectangle over it isn't an option.

    Thanks again for everyones continued help.

    Moray

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    38

    RE: Sprites on J2ME (again)

    Hi Moray.
    The fastest way to redraw the screen would probably be achieved redrawing only the portions of your Canvas/FullCanvas that has to change after you sprite movement. A simple way to do this is to use the setClip(...) method in javax.microedition.lcdui.Graphics specifying a clip rectangle that includes the previous sprite position and its new one [alternatively you can use repaint(x,y,width,height) as specified in javax.microedition.lcdui.Graphics]. The paint(...) method will then repaint only the pixels in that area.
    A problem arises if you have more than one sprite moving on the screen at the same time in a different area of the screen:
    two setClip(...) calls in the same paint method force a repaint of a rectangular area that consists of the smaller possible rectangle including all the clip rectangles defined by the setClip calls.
    This could add a lot of "dirty" code to your reapaint routines without being much useful if two or more sprites on the screen are slightly far from each other (the paint method will repaint a portion of the screen that is almost the same size of the Canvas).
    This depends from your type of game (an RPG-like game will probably require less full-repaints of the Canvas than an arcade-like one).
    You should find out the right balance among all the different factors that determine your gameplay (scrolling-fixed backgrounds, dedicated area for sprite movement, number of sprites on screen etc..).
    In general it will be a matter of game design, gameplay, clip areas and double buffering.

    Hope this can help somehow
    cheers

    davide
    <AtomicTag.com/>

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    19

    RE: Sprites on J2ME (again)

    Personally I've never found there to be any significant performance hit if you re-draw the entire background, even with dozens of sprites moving around. This way you'll never have to worry about 'sprite smudge'.

    If you have a scrolling game, make sure you only render the sprite when it's on screen (obvious, I know, but a couple of x,y checks can really help speed things up).

    One possible performance hit with this full repaint arises if your full screen background image contains lots of colours - try to keep the number of colours on a background image to about 16 or under. The more colours, the slower it takes to paint.

    Good work on creating your own sprite class. I did this at one time, but I found it was a lot slower than using simple integer arrays to specify behaviour/movement (maybe I was doing it wrong . My solution isn't as pure object-oriented, but you can have a lot more sprites around without slowdown. Stick with what you have for now, and see how it goes.

    ross

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    87

    RE: Sprites on J2ME (again)

    I'm having a similar problem with the trailing effect created by moving sprites, I am using my own animated sprite class and I'm repainting the full screen every time, I really don't understand why this is happening.
    Could it be the nature of the Nokia screen causing it ?
    I've never had this problem when programming games in applets.

    I'm quite impressed with the performance of the Nokia Series 40 phones, there is no slowdown and I can refresh at 20 fps with no problem, there is just this ghosting problem with moving sprites.

    I have also dabbled with double buffering, but it solved nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×