<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jappit.com &#187; transition</title>
	<atom:link href="http://www.jappit.com/blog/tag/transition/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jappit.com/blog</link>
	<description>Mobile blog by Alessandro La Rosa</description>
	<lastBuildDate>Wed, 23 Nov 2011 10:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>J2ME Image effects part 2: sliding transitions</title>
		<link>http://www.jappit.com/blog/2008/05/22/j2me-image-effects-part-2-sliding-transitions/</link>
		<comments>http://www.jappit.com/blog/2008/05/22/j2me-image-effects-part-2-sliding-transitions/#comments</comments>
		<pubDate>Thu, 22 May 2008 14:46:13 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[image effect]]></category>
		<category><![CDATA[sliding]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=44</guid>
		<description><![CDATA[After an explosive J2ME class, now it&#8217;s the time for sliding transition effects. With the following SlidingImage class you&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>After an <a title="Explode effect for J2ME images" href="http://www.jappit.com/blog/2008/05/20/let-your-images-explode-in-j2me/">explosive J2ME class</a>, now it&#8217;s the time for sliding transition effects. With the following SlidingImage class you&#8217;ll be able to seamlessly add both SlideIn and SlideOut effects to your toooo static apps!</p>
<p><img src="http://www.jappit.com/images/blog/uploads/j2me_sliding_effect.png" alt="J2ME sliding transition effect screenshot" width="311" height="219" /></p>
<p>As usual, take a look at how <a title="J2ME slide transition effect in action" href="http://www.jappit.com/index.php?page=emulator&amp;midlet=image_slide">this would appear in a real phone</a>, and then proceed with the simple these 1,2,3 steps <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ol>
<li><strong>Download</strong> and include in your code the <a title="SlidingImage class source code" href="http://www.jappit.com/uploads/src/SlidingImage.java">SlidingImage.java</a> class</li>
<li><strong>Instantiate </strong>a new SlidingImage:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">SlidingImage image <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SlidingImage<span style="color: #009900;">&#40;</span>
	<span style="color: #003399;">Image</span>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/image1.png&quot;</span><span style="color: #009900;">&#41;</span>,
	<span style="color: #cc66cc;">10</span>,
	SlidingImage.<span style="color: #006633;">SLIDE_OUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>These are the constructor arguments:</p>
<ul>
<li>An Image object to be slided</li>
<li>The number of pieces of the sliding image</li>
<li style="text-align: left;">The type of slide, can be SlidingImage.SLIDE_IN or SlidingImage.SLIDE_OUT</li>
</ul>
</li>
<li><strong>Start the sliding effect</strong>, specifying its direction and duration (in milliseconds):

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">image.<span style="color: #006633;">slide</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Canvas</span>.<span style="color: #006633;">RIGHT</span>, <span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Direction can be one of <strong>Canvas</strong> properties <em>UP, RIGHT, DOWN and LEFT</em>.</li>
<li>Now you can <strong>paint </strong>it simply specifying coordinates and an anchor, as usual:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">image.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g,
	<span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">100</span>,
	<span style="color: #003399;">Graphics</span>.<span style="color: #006633;">HCENTER</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">VCENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>If you remember ExplodingImage class, you can check if effect is ended with the public <strong>ended </strong>property:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image.<span style="color: #006633;">ended</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//effect-end related code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>If you want to reset the effect, also changing the sliding image pieces and effect type (slide in or out), you can use the <strong>reset()</strong> method:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//to reset changing also slides and type properties</span>
image.<span style="color: #006633;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span>, SlidingImage.<span style="color: #006633;">SLIDE_IN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//otherwise, to simply reset:</span>
image.<span style="color: #006633;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ol>
<p>You can download source code here:</p>
<ul>
<li><a title="SlidingImage j2me class source code" href="http://www.jappit.com/uploads/src/SlidingImage.java">SlidingImage.java</a>: <strong>main class</strong> source code</li>
<li><a title="J2ME sample Canvas using SlidingImage" href="http://www.jappit.com/uploads/src/SimpleSlidingCanvas.java">SimpleSlidingCanvas.java</a>: <strong>example of Canvas</strong> using SlidingImage</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/05/22/j2me-image-effects-part-2-sliding-transitions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Let your images explode in J2ME!</title>
		<link>http://www.jappit.com/blog/2008/05/20/let-your-images-explode-in-j2me/</link>
		<comments>http://www.jappit.com/blog/2008/05/20/let-your-images-explode-in-j2me/#comments</comments>
		<pubDate>Tue, 20 May 2008 09:26:17 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=42</guid>
		<description><![CDATA[After a MIDP 1.0 utility to rotate images now time has come for some image fun When writing mobile applications, it&#8217;s always cool to add some effects or transitions. But, while for example FlashLite has a nice builtin support for them, with J2ME you have to hand-code even the simplest movement (and this is the [...]]]></description>
			<content:encoded><![CDATA[<p>After <a title="Rotate images in J2ME using MIDP 1.0" href="http://www.jappit.com/blog/2008/05/19/rotating-images-in-j2me-using-midp-10/">a MIDP 1.0 utility to rotate images</a> now time has come for some image fun <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://www.jappit.com/images/blog/uploads/j2me_image_explode.png" alt="J2ME Image explode effect screenshot" width="302" height="196" /><br />
When writing mobile applications, it&#8217;s always cool to add some effects or transitions. But, while for example FlashLite has a nice builtin support for them, with J2ME you have to hand-code even the simplest movement (and this is the main reason why most J2ME apps are all but attractive).</p>
<p>So, here&#8217;s a first class that you can use to add an &#8220;explode&#8221; effect to images in a straightforward way. How to do it? Here we come:</p>
<ol>
<li><strong>Download</strong> the <a title="ExplodingImage.java source code" href="http://www.jappit.com/uploads/src/ExplodingImage.java">ExplodingImage.java</a> source code and put it straight in your project</li>
<li><strong>Instantiate</strong> an ExplodingImage this way:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//get your Image</span>
<span style="color: #003399;">Image</span> sourceImage <span style="color: #339933;">=</span> <span style="color: #003399;">Image</span>.<span style="color: #006633;">createImage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/image.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//and then use it in ExplodingImage constructor</span>
ExplodingImage image <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExplodingImage<span style="color: #009900;">&#40;</span>sourceImage , <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The ExplodingImage constructor accepts the following arguments:</p>
<ul>
<li>An <em>Image</em> instance</li>
<li>An <em>int</em> representing the <strong>&#8220;level&#8221;</strong> for the exploding effect, that is the <em>strength </em>of the effect itself (higher the level, stronger the effect).</li>
<li>The last 2 <em>int</em> arguments represent the horizontal and vertical pieces of the exploded image.</li>
</ul>
</li>
<li><strong>Start</strong> the explode effect with the explode() method, that will accept the effect duration as argument:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">image.<span style="color: #006633;">explode</span><span style="color: #009900;">&#40;</span>2000L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>To <strong>paint</strong> it, simply use its paint() method, very similary to the Graphics drawImage() one. For example, in a Canvas paint() method, you can do something like this:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> paint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	g.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>0xffffff<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	g.<span style="color: #006633;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, width, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	image.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g, getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">HCENTER</span> <span style="color: #339933;">|</span> <span style="color: #003399;">Graphics</span>.<span style="color: #006633;">VCENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To give the effect a &#8220;smooth&#8221; animation, you should paint it quite frequently (let&#8217;s say, not once per second <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). So, always using Canvas, a sample code could be like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		repaint<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">synchronized</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				wait<span style="color: #009900;">&#40;</span>50L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>To <strong>test if the effect has ended</strong>, you can simply access your ExplodingImage <em>ended</em> instance variable:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image.<span style="color: #006633;">ended</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//effect-end related code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>And you&#8217;re done! See it in action here: <a title="J2ME explode effect in emulator" href="http://www.jappit.com/index.php?page=emulator&amp;midlet=image_explode">J2ME image explode effect in action</a></li>
</ol>
<p>Sample source code is available here:</p>
<ul>
<li><a title="ExplodingImage.java source code" href="http://www.jappit.com/uploads/src/ExplodingImage.java">ExplodingImage.java</a>: main class</li>
<li><a title="ExploginImageCanvas.java source code" href="http://www.jappit.com/uploads/src/ExplodingImageCanvas.java">ExplodingImageCanvas.java</a>: sample usage of ExplodingImage within a Canvas</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/05/20/let-your-images-explode-in-j2me/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

