开发者

Do screen transitions when the user clicks on a bitmap

I am working on an eBook app where I need to transition the screens from left to right and right to left. I tried many samples that I've found, but I am not successful. How do I change the screen frequently when user clicks on the screen from left to right and right to left. What is the basic idea for transition of pages. I went through the Developer Support Forum thread "page-flip effect" looking for a solution, but I can't see it.

The following code is not logical. In which position do I have to implement flip effect for flipping pages in the screen and how to implement it?

public class TransitionScreen extends FullScreen implements Runnable{

     private int angle = 0;
     Bitmap fromBmp,toBmp;

    public TransitionScreen(){

    }
    public TransitionScreen(AnimatableScreen from,AnimatableScreen to) {

           fromBmp = new Bitmap(Display.getWidth(), Display.getHeight());
           toBmp = new Bitmap(Display.getWidth(), Display.getHeight());
         Graphics fromGraphics =  Graphics.create(fromBmp);
         Graphics toGraphics =  Graphics.create(toBmp);

         Object eventLock = getApplication().getEventLock();

         synchronized(eventLock) {

              from.drawAnimationBitmap(fromGraphics);

              to.drawAnimationBitmap(toGraphics);
             // Interpolate myOffset to target

             // Set animating = false if myOffset = target

             invalidate();
         } 

        try {
            synchronized (Application.getEventLock()) {
                Ui.getUiEng开发者_Python百科ine().suspendPainting(true);
            }

        } catch (final Exception ex) {

        }

    }

    protected void paint(Graphics g){

           //control x,y positions of the bitmaps in the timer task and the paint will just paint where they go

        g.drawBitmap(0,0, 360,
                480, toBmp, 0, 0);
        g.drawBitmap(0, 0, 360,
                480, fromBmp, 0, 0);     
//      invalidate();

        }

    protected boolean touchEvent(TouchEvent event) {
        if (!this.isFocus())
            return true;
        if (event.getEvent() == TouchEvent.CLICK) {      

    //      invalidate();
        }
        return super.touchEvent(event);
    }

}


Assuming you're working with version 5.0 or later of the OS, this page has a simple example:

http://docs.blackberry.com/en/developers/deliverables/11958/Screen_transitions_detailed_overview_806391_11.jsp

From where did you get the code sample posted in your question? That code does not appear to be close to working.

Update: you can actually animate transitions like this yourself fairly simply. Assuming you know how to use the Timer class, you basically have a class-level variable that stores the current x-position of your first Bitmap (the variable would have a value of 0 initially). In each timer tick, you subtract some amount from the x-position (however many pixels you want it to move each tick) and then call invalidate();.

In each call to the paint method, then, you just draw the first bitmap using the x-position variable for the call's x parameter, and draw the second bitmap using the x-position variable plus the width of the first bitmap. The resulting effect is to see the first bitmap slide off to the left while the second slides in from the right.

A caveat : Because this is java (which means the timer events are not real-time - they're not guaranteed to occur when you want them to), this animation will be kind of erratic and unsmooth. The best way to get smooth animation like this is to pre-render your animation cells (where each is a progressive combination of the two bitmaps you're transitioning between), so that in the paint method you're just drawing a single pre-rendered bitmap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜