J2ME Image effects part 2: sliding transitions
After an explosive J2ME class, now it’s the time for sliding transition effects. With the following SlidingImage class you’ll be able to seamlessly add both SlideIn and SlideOut effects to your toooo static apps!
As usual, take a look at how this would appear in a real phone, and then proceed with the simple these 1,2,3 steps
- Download and include in your code the SlidingImage.java class
- Instantiate a new SlidingImage:
SlidingImage image = new SlidingImage( Image.createImage("/image1.png"), 10, SlidingImage.SLIDE_OUT);
These are the constructor arguments:
- An Image object to be slided
- The number of pieces of the sliding image
- The type of slide, can be SlidingImage.SLIDE_IN or SlidingImage.SLIDE_OUT
- Start the sliding effect, specifying its direction and duration (in milliseconds):
image.slide(Canvas.RIGHT, 3000);
Direction can be one of Canvas properties UP, RIGHT, DOWN and LEFT.
- Now you can paint it simply specifying coordinates and an anchor, as usual:
image.paint(g, 100, 100, Graphics.HCENTER | Graphics.VCENTER);
- If you remember ExplodingImage class, you can check if effect is ended with the public ended property:
if(image.ended) { //effect-end related code }
- If you want to reset the effect, also changing the sliding image pieces and effect type (slide in or out), you can use the reset() method:
//to reset changing also slides and type properties image.reset(12, SlidingImage.SLIDE_IN); //otherwise, to simply reset: image.reset();
You can download source code here:
- SlidingImage.java: main class source code
- SimpleSlidingCanvas.java: example of Canvas using SlidingImage
J2ME, Flash Lite, Symbian, Iphone, Android and Ajax news, tutorials, source code » Blog Archive » ImageFx: J2ME image effects library 2:38 pm on June 6, 2008 Permalink
[...] two tutorials on Image animations in J2ME, I’ve finally decided to put together a library to [...]
Absar 9:14 am on February 10, 2009 Permalink
nice
rohit 11:32 am on September 23, 2010 Permalink
really nice article.. good work!!