{"id":461,"date":"2011-07-23T22:34:00","date_gmt":"2011-07-23T22:34:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/android-game-development-sprite-animation.html"},"modified":"2012-10-21T19:58:20","modified_gmt":"2012-10-21T19:58:20","slug":"android-game-development-sprite","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html","title":{"rendered":"Android Game Development &#8211; Sprite Animation"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">If you followed the <a href=\"http:\/\/www.javacodegeeks.com\/?tag=android-games\">series<\/a> so far we are pretty knowledgable in handling touches, displaying images and moving them around.<\/p>\n<p>But a moving image it\u2019s a pretty dull sight as it looks really fake and amateurish. To give the characters some life we will need to do more than that. That is what animation is all about. A rock is an inanimate object and even if it is thrown, it doesn\u2019t change its shape. A human on the other hand, is very animated. Try throwing one and you\u2019ll see twitching limbs and even screams in the air.<\/p>\n<p>Let\u2019s just resort to examining walking which is pretty complex in its own. Imagine a human crossing your way (just in 2D). You\u2019ll notice different displays of the body. Left foot in front, right hand in front while the oposite limbs are behind. This slowly changes so the left foot remains behind while the right progresses along with the body. But at one point the cycle repeats. If you don\u2019t close your eyes you see the person progressing smoothly. If you close your eyes and keep them closed for a bit and open them again the person already went on and is in a different position. Try blinking quite rapidly and you will see something like the old black and white comedies. That is low frame rate. More on FPS <a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-loop.html\">here<\/a>.<\/p>\n<p>Actually we do want a low frame rate walking for this tutorial, just like this.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine_anim.gif\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine_anim.gif\" \/><\/a><\/div>\n<p>The walking presented above is a bit dodgy but it\u2019s a ripped off version of the sprites from Monkey Island. She\u2019s Elaine Marley.<br \/>\nThis is called a <strong>Sprite<\/strong>. It is a simple 2 dimensional image or animation.<br \/>\nTo be able to re-create the above animation, we need every frame from the walking cycle.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine.png\" \/><\/a><\/div>\n<p>It is a 150 pixels wide image and each frame is 30 pixels wide.<br \/>\nTo illustrate it better check the following image.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine_frames.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_elaine_frames.png\" \/><\/a><\/div>\n<p>To get the above animation in android (or iPhone or in any other program for that matter), we need to load up each frame as a separate image and display them at regular intervals one after each other. OR we can load up the big image containing all the frames and use the methods provided by android do slice and dice them on the fly and to display only the relevant frame.<br \/>\nTo do that is trivial. We know that we have 5 frames and each frame is 30 pixels wide. We define a rectangle (that will be our selection) which has the width of one frame and the height of the image.<br \/>\nThe following image shows how I cut out the first two frames. The rest you should fill in.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_frames_cut.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/walk_frames_cut.png\" \/><\/a><\/div>\n<p>Knowing all this let\u2019s go create the project. We will use the knowledge from some previous chapters, most notably about the <a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-loop.html\">game loop<\/a> and the one about the <a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html\">image display<\/a> (here we set up the thread that triggers the drawing of the graphics item every frame).<\/p>\n<p>We will need an object to animate. We use Elaine from Monkey Island so I will the class <strong><i>ElaineAnimated.java<\/i><\/strong>.<\/p>\n<pre class=\"brush:java\">public class ElaineAnimated {\r\n\r\n\tprivate static final String TAG = ElaineAnimated.class.getSimpleName();\r\n\r\n\tprivate Bitmap bitmap;\t\t\/\/ the animation sequence\r\n\tprivate Rect sourceRect;\t\/\/ the rectangle to be drawn from the animation bitmap\r\n\tprivate int frameNr;\t\t\/\/ number of frames in animation\r\n\tprivate int currentFrame;\t\/\/ the current frame\r\n\tprivate long frameTicker;\t\/\/ the time of the last frame update\r\n\tprivate int framePeriod;\t\/\/ milliseconds between each frame (1000\/fps)\r\n\r\n\tprivate int spriteWidth;\t\/\/ the width of the sprite to calculate the cut out rectangle\r\n\tprivate int spriteHeight;\t\/\/ the height of the sprite\r\n\r\n\tprivate int x;\t\t\t\t\/\/ the X coordinate of the object (top left of the image)\r\n\tprivate int y;\t\t\t\t\/\/ the Y coordinate of the object (top left of the image)\r\n\r\n}\r\n<\/pre>\n<p>The private attributes are commented but worth mentioning a few.<\/p>\n<ul style=\"text-align: left\">\n<li><strong><i>bitmap<\/i><\/strong> is the png file containing all the frames. The second image in this article.<\/li>\n<li><strong><i>sourceRect<\/i><\/strong> is the selection rectangle. It is the blue window in the image above. The rectangle moves every frame onto the next.<\/li>\n<li><strong><i>frameTicker<\/i><\/strong> this is the java timestamp of the last frame change in the walking sequence. <strong>Note<\/strong> that this is not the game FPS but the walking FPS. If we want Elaine to perform a complete walk cycle in a second we set the frame rate for walking to <strong>5<\/strong> because we have 5 frames. To get a really smooth animation we need 30 frames but it\u2019s not the point now.<\/li>\n<li><strong><i>framePeriod<\/i><\/strong> is time in milliseconds that represents the period of time a frame is being displayed. If the cycle completes in 1 second that means for <strong>5<\/strong> frames the period will be <strong>0.2<\/strong> seconds. That is, each frame will be displayed for 0.2 seconds.<\/li>\n<\/ul>\n<p>The constructor is as follows:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">public ElaineAnimated(Bitmap bitmap, int x, int y, int width, int height, int fps, int frameCount) {\r\n\t\tthis.bitmap = bitmap;\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t\tcurrentFrame = 0;\r\n\t\tframeNr = frameCount;\r\n\t\tspriteWidth = bitmap.getWidth() \/ frameCount;\r\n\t\tspriteHeight = bitmap.getHeight();\r\n\t\tsourceRect = new Rect(0, 0, spriteWidth, spriteHeight);\r\n\t\tframePeriod = 1000 \/ fps;\r\n\t\tframeTicker = 0l;\r\n\t}\r\n<\/pre>\n<p>I\u2019m assuming that the frames are the same width so I calculate the width of the rectangle by dividing the width of the image with the number of frames. I also pass in the <strong><i>fps<\/i><\/strong> which is again, the frames per second of the walk cycle not the game FPS.<\/p>\n<p>Elaine will have an <strong><i>update<\/i><\/strong> method of her own as she is an animated object and she needs to look good and she is in charge of dragging her feet. Because the period of the game update cycle and Elaine\u2019s one might be (in this case is) different we pass the actual game time as a variable so we know when we need to display the next frame.<br \/>\nFor example the game runs very fast and the update is called every 20 milliseconds and we need to update the frame every 200ms, then the progression of the frame will happen at every 10th game update.<\/p>\n<p>Here\u2019s the code:<\/p>\n<pre class=\"brush:java\">public void update(long gameTime) {\r\n\tif (gameTime &gt; frameTicker + framePeriod) {\r\n\t\tframeTicker = gameTime;\r\n\t\t\/\/ increment the frame\r\n\t\tcurrentFrame++;\r\n\t\tif (currentFrame &gt;= frameNr) {\r\n\t\t\tcurrentFrame = 0;\r\n\t\t}\r\n\t}\r\n\t\/\/ define the rectangle to cut out sprite\r\n\tthis.sourceRect.left = currentFrame * spriteWidth;\r\n\tthis.sourceRect.right = this.sourceRect.left + spriteWidth;\r\n}\r\n<\/pre>\n<p>The update is called from the main game panel (check previous entries how that works). This is the update method of the <strong><i>MainGamePanel<\/i><\/strong> class.<\/p>\n<pre class=\"brush:java\">public void update() {\r\n\telaine.update(System.currentTimeMillis());\r\n}\r\n<\/pre>\n<p>The <strong><i>update<\/i><\/strong> method is simple (Elaine\u2019s). It increments the frame if the passed in time (which is the system time when the update method was called) is greater than the last time (<strong><i>frameTicker<\/i><\/strong>) the frame was updated plus the period of the next update.<br \/>\nIf the next frame is beyond the last, we reset the cycle.<\/p>\n<p>After all that area from which the image will be cut out is defined as the <strong><i>sourceRect<\/i><\/strong>.<br \/>\nThat\u2019s it. Now let\u2019s go on to display it.<\/p>\n<pre class=\"brush:java\">public void draw(Canvas canvas) {\r\n\t\t\/\/ where to draw the sprite\r\n\t\tRect destRect = new Rect(getX(), getY(), getX() + spriteWidth, getY() + spriteHeight);\r\n\t\tcanvas.drawBitmap(bitmap, sourceRect, destRect, null);\r\n\t}\r\n<\/pre>\n<p>That is all. We set the destination rectangle as to where to draw the cut out image. It is at Elaine\u2019s position (X and Y set in the constructor).<\/p>\n<pre class=\"brush:java\">canvas.drawBitmap(bitmap, sourceRect, destRect, null);\r\n<\/pre>\n<p>tells android to cut out the image defined by <strong><i>sourceRect<\/i><\/strong> from the image contained in <strong><i>bitmap<\/i><\/strong> and draw it into the rectangle on the canvas defined by <strong><i>destRect<\/i><\/strong>.<\/p>\n<p>The <strong><i>draw<\/i><\/strong> is called from the game panel\u2019s render method triggered by the game loop (check previous entries).<\/p>\n<p>The <strong><i>MainGamePanel.java<\/i><\/strong> differs slightly from the one from previous chapters. I got rid of all the droidz and added just Elaine.<\/p>\n<pre class=\"brush:java\">private ElaineAnimated elaine;\r\n\r\n\tpublic MainGamePanel(Context context) {\r\n\t\t\/\/* ... removed ... *\/\r\n\r\n\t\t\/\/ create Elaine and load bitmap\r\n\t\telaine = new ElaineAnimated(\r\n\t\t\t\tBitmapFactory.decodeResource(getResources(), R.drawable.walk_elaine)\r\n\t\t\t\t, 10, 50\t\/\/ initial position\r\n\t\t\t\t, 30, 47\t\/\/ width and height of sprite\r\n\t\t\t\t, 5, 5);\t\/\/ FPS and number of frames in the animation\r\n\r\n\t\t\/\/ create the game loop thread\r\n\t\tthread = new MainThread(getHolder(), this);\r\n\r\n\t\t\/\/* ... removed ... *\/\r\n\t}\r\n<\/pre>\n<p>Elaine is instantiated in the panel\u2019s constructor and is given an initial positon of (X=10, Y=50). I pass in the width and the height of the sprite too but that is ignored anyway, but you can modify the code.<br \/>\nThe FPS is very important and the number of frames too. FPS says how many frames are to be shown in one second. The last parameter is the number of frames in the cycle.<\/p>\n<p>The thread and activity classes haven\u2019t changed at all. You can find them in the download as they are quite long to be pasted. The image is named <strong><i>walk_elaine.png<\/i><\/strong> and it was copied to <strong><i>\/res\/drawable-mdpi\/<\/i><\/strong> so android can pick it up automatically.<\/p>\n<p>If you run the application you should be seeing Elaine performing walking cycles in one place. We should have used jumping as that can be performed in one place but you get the idea.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/Screen-shot-2010-09-10-at-00.38.00.png\"><img decoding=\"async\" border=\"0\" height=\"132\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/Screen-shot-2010-09-10-at-00.38.00.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\"><span class=\"Apple-style-span\" style=\"color: #444444;font-family: verdana;line-height: 17px\">Elaine Walking<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Enhancement<\/span><\/strong><\/p>\n<p>To make some neat additions modify Elaine\u2019s <strong><i>draw<\/i><\/strong> method so it displays the original image containing the sprites from which the frames are extracted.<\/p>\n<pre class=\"brush:java\">public void draw(Canvas canvas) {\r\n\t\/\/ where to draw the sprite\r\n\tRect destRect = new Rect(getX(), getY(), getX() + spriteWidth, getY() + spriteHeight);\r\n\tcanvas.drawBitmap(bitmap, sourceRect, destRect, null);\r\n\tcanvas.drawBitmap(bitmap, 20, 150, null);\r\n\tPaint paint = new Paint();\r\n\tpaint.setARGB(50, 0, 255, 0);\r\n\tcanvas.drawRect(20 + (currentFrame * destRect.width()), 150, 20 + (currentFrame * destRect.width()) + destRect.width(), 150 + destRect.height(),  paint);\r\n}\r\n<\/pre>\n<p>This just displays the image at (20, 150) and creates a new paint object so we can paint over the current frame on the original image.<br \/>\nThe method <strong><i>setARGB<\/i><\/strong> creates a semi-transparent green paint. The first value is <strong>50<\/strong> which means it\u2019s 75% transparent. <strong>0<\/strong> is completely transparent while <strong>255<\/strong> is fully opaque.<br \/>\nAfter everything was drawn we paint a rectangle of the size of a frame onto the original image so you see which frame is being displayed in the motion.<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto;margin-right: auto;text-align: center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><a href=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/Screen-shot-2010-09-10-at-00.43.02.png\"><img decoding=\"async\" border=\"0\" height=\"216\" src=\"http:\/\/obviam.net\/wp-content\/uploads\/2010\/09\/Screen-shot-2010-09-10-at-00.43.02.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center\"><span class=\"Apple-style-span\" style=\"color: #444444;font-family: verdana;line-height: 17px\">Walking with Current Frame Painted<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>That\u2019s it. Run it and you have your first sprite animation.<\/p>\n<p>Download the source code <a href=\"http:\/\/obviam.net\/source_code\/animation_walk.tar.gz\">here (animation_walk.tar.gz)<\/a><\/p>\n<p><strong>Reference:<\/strong>&nbsp;<a href=\"http:\/\/obviam.net\/index.php\/sprite-animation-with-android\/\">Sprite Animation with Android<\/a>&nbsp;from our&nbsp;<a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG<\/a>&nbsp;partner Tamas Jano&nbsp;from &#8220;<a href=\"http:\/\/obviam.net\/\">Against The Grain<\/a>&#8221; blog.<\/p>\n<div style=\"margin: 0px\">Do not forget to check out our new <strong><i>Android Game<\/i><\/strong> <strong><i><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/jcg-studios-arkdroid-official-launch.html\">ArkDroid<\/a>&nbsp;<span class=\"Apple-style-span\" style=\"font-weight: normal\"><span class=\"Apple-style-span\" style=\"font-style: normal\">(screenshots below)<\/span><\/span><\/i><\/strong>. You feedback will be more than helpful!<\/div>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/3.bp.blogspot.com\/-n99pqdxWzqM\/ThBFy-5CGmI\/AAAAAAAAABg\/LfSrtmW-RaQ\/s1600\/multiple_laser.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/3.bp.blogspot.com\/-n99pqdxWzqM\/ThBFy-5CGmI\/AAAAAAAAABg\/LfSrtmW-RaQ\/s200\/multiple_laser.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s1600\/multiple_sticky.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-sEqMxR7YZnY\/ThBGdHcIYnI\/AAAAAAAAABs\/S6iKs2lycyk\/s200\/multiple_sticky.jpg\" width=\"133\" \/><\/a><a href=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s1600\/arkdroid_ingame.jpg\"><img decoding=\"async\" border=\"0\" height=\"200\" src=\"http:\/\/1.bp.blogspot.com\/-0dr410FpxAA\/TgdJc44bfvI\/AAAAAAAAADg\/GyMLvayT_rc\/s200\/arkdroid_ingame.jpg\" width=\"133\" \/><\/a><\/div>\n<div style=\"margin: 0px\"><strong>Related Articles:<\/strong><\/div>\n<ul style=\"text-align: left\">\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/android-game-development-tutorials.html\">Android Game Development Tutorials Introduction<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-idea.html\">Android Game Development &#8211; The Game Idea<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-create-project.html\">Android Game Development &#8211; Create The Project<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game.html\">Android Game Development &#8211; A Basic Game Architecture<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-basic-game_05.html\">Android Game Development &#8211; A Basic Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-displaying.html\">Android Game Development &#8211; Displaying Images with Android<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-moving-images.html\">Android Game Development &#8211; Moving Images on Screen<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-game-loop.html\">Android Game Development &#8211; The Game Loop<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-measuring-fps.html\">Android Game Development &#8211; Measuring FPS<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-particle.html\">Android Game Development &#8211; Particle Explosion<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/android-game-development-design-in-game.html\">Android Game Development &#8211; Design In-game Entities &#8211; The Strategy Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-using-bitmap.html\">Android Game Development &#8211; Using Bitmap Fonts<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/android-game-development-switching-from.html\">Android Game Development &#8211; Switching from Canvas to OpenGL ES<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-displaying.html\">Android Game Development \u2013 Displaying Graphical Elements (Primitives) with OpenGL ES<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-opengl-texture.html\">Android Game Development \u2013 OpenGL Texture Mapping<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/android-game-development-design-in-game.html\">Android Game Development \u2013 Design In-game Entities \u2013 The State Pattern<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/?tag=android-games\">Android Games Article Series<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a pretty dull sight as it looks really fake and amateurish. To give the characters some life we will need to do more than that. That is what animation is &hellip;<\/p>\n","protected":false},"author":27,"featured_media":46,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-games"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Game Development - Sprite Animation - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Game Development - Sprite Animation - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-23T22:34:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T19:58:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Impaler\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Impaler\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html\"},\"author\":{\"name\":\"Impaler\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\"},\"headline\":\"Android Game Development &#8211; Sprite Animation\",\"datePublished\":\"2011-07-23T22:34:00+00:00\",\"dateModified\":\"2012-10-21T19:58:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html\"},\"wordCount\":1509,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"articleSection\":[\"Android Games\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html\",\"name\":\"Android Game Development - Sprite Animation - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"datePublished\":\"2011-07-23T22:34:00+00:00\",\"dateModified\":\"2012-10-21T19:58:20+00:00\",\"description\":\"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/07\\\/android-game-development-sprite.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android Games\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/android\\\/android-games\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Android Game Development &#8211; Sprite Animation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6bad1a2db4fb0129703629617c049f8c\",\"name\":\"Impaler\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g\",\"caption\":\"Impaler\"},\"sameAs\":[\"http:\\\/\\\/obviam.net\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Impaler\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Game Development - Sprite Animation - Java Code Geeks","description":"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html","og_locale":"en_US","og_type":"article","og_title":"Android Game Development - Sprite Animation - Java Code Geeks","og_description":"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a","og_url":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-07-23T22:34:00+00:00","article_modified_time":"2012-10-21T19:58:20+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","type":"image\/jpeg"}],"author":"Impaler","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Impaler","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html"},"author":{"name":"Impaler","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c"},"headline":"Android Game Development &#8211; Sprite Animation","datePublished":"2011-07-23T22:34:00+00:00","dateModified":"2012-10-21T19:58:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html"},"wordCount":1509,"commentCount":10,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","articleSection":["Android Games"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html","url":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html","name":"Android Game Development - Sprite Animation - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","datePublished":"2011-07-23T22:34:00+00:00","dateModified":"2012-10-21T19:58:20+00:00","description":"If you followed the series so far we are pretty knowledgable in handling touches, displaying images and moving them around. But a moving image it\u2019s a","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/07\/android-game-development-sprite.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/www.javacodegeeks.com\/category\/android"},{"@type":"ListItem","position":3,"name":"Android Games","item":"https:\/\/www.javacodegeeks.com\/category\/android\/android-games"},{"@type":"ListItem","position":4,"name":"Android Game Development &#8211; Sprite Animation"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6bad1a2db4fb0129703629617c049f8c","name":"Impaler","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/def7cf34ac1eee0f6c2de98be951379d6bf14fd498acf7d3864e2e570ece357c?s=96&d=mm&r=g","caption":"Impaler"},"sameAs":["http:\/\/obviam.net\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Impaler"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}