<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Playing animation just once.</title>
		<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once</link>
		<description>Posts in the discussion thread &quot;Playing animation just once.&quot; - How to play a sprite animation just once.</description>
				<copyright></copyright>
		<lastBuildDate>Fri, 06 Mar 2026 11:43:38 +0000</lastBuildDate>
		
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2024336</guid>
				<title>(no title)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2024336</link>
				<description></description>
				<pubDate>Fri, 02 May 2014 19:22:01 +0000</pubDate>
				<wikidot:authorName>PiscesMike</wikidot:authorName>				<wikidot:authorUserId>1721619</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Oh yeah! Game is looking nice, Borparo. I looked at those the other day, don't know why it slipped my mind to say it looked good. Keep up the excellent work!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2023310</guid>
				<title>(no title)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2023310</link>
				<description></description>
				<pubDate>Thu, 01 May 2014 06:29:26 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>oh well!, :D i didn't realized it until you mentioned i was not logged in :D</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2022167</guid>
				<title>(no title)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2022167</link>
				<description></description>
				<pubDate>Tue, 29 Apr 2014 17:46:09 +0000</pubDate>
				<wikidot:authorName>rbwhitaker</wikidot:authorName>				<wikidot:authorUserId>88099</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>This looks pretty cool, Borja! Thanks for sharing! (I fixed the links so they work directly.)</p> <p>Though&#8230; I can't understand why you didn't log into your account to post the links. :D The more posts you make, the sooner your karma goes up, and the sooner you'll be able to post links on your own without trouble.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2022154</guid>
				<title>(no title)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2022154</link>
				<description></description>
				<pubDate>Tue, 29 Apr 2014 17:36:17 +0000</pubDate>
				<wikidot:authorName>Borja Panadero</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Hi rbwhitaker,<br /> Thanks, i copied below some screenshots of the game</p> <p><a href="http://gatogrisgames.com/wp-content/uploads/2014/04/promo01.png">http://gatogrisgames.com/wp-content/uploads/2014/04/promo01.png</a><br /> <a href="http://gatogrisgames.com/wp-content/uploads/2014/04/promo02.png">http://gatogrisgames.com/wp-content/uploads/2014/04/promo02.png</a><br /> <a href="http://gatogrisgames.com/wp-content/uploads/2014/04/promo03.png">http://gatogrisgames.com/wp-content/uploads/2014/04/promo03.png</a><br /> <a href="http://gatogrisgames.com/wp-content/uploads/2014/04/promo04.png">http://gatogrisgames.com/wp-content/uploads/2014/04/promo04.png</a><br /> <a href="http://gatogrisgames.com/wp-content/uploads/2014/04/promo05.png">http://gatogrisgames.com/wp-content/uploads/2014/04/promo05.png</a></p> <p>and this is the link to the page where you can try the alpha of the game:</p> <p><a href="http://gatogrisgames.com/?page_id=410">http://gatogrisgames.com/?page_id=410</a></p> <p>Thanks a lot for the help :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2020599</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2020599</link>
				<description></description>
				<pubDate>Sun, 27 Apr 2014 16:09:38 +0000</pubDate>
				<wikidot:authorName>rbwhitaker</wikidot:authorName>				<wikidot:authorUserId>88099</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>boparo, it's annoying, I'll admit. I wish I had more control over things like that, but it's a Wikidot limitation that I have no control over. It shouldn't take very many posts to get that privilege though.</p> <p>If you want to post a link, though, just post something &quot;close&quot; to the URL (like &quot;www (dot) google (dot) com&quot;) and I'll edit your post to make it work right.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2020420</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2020420</link>
				<description></description>
				<pubDate>Sun, 27 Apr 2014 07:35:05 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi PiscesMike,</p> <p>Apologies, seems at the moment i'm not able of adding links in the posts, i need more karma :)</p> <p>Right now i'm focused in a better collision system, :D the one i did is very simple, and the ball get's stack over the<br /> paddle sometimes. I also want to prepare 2 more things. First a difficulty level for when playing against the computer, and second, a power up system.<br /> Hope to be able to show more things soon :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2018930</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2018930</link>
				<description></description>
				<pubDate>Thu, 24 Apr 2014 20:41:08 +0000</pubDate>
				<wikidot:authorName>PiscesMike</wikidot:authorName>				<wikidot:authorUserId>1721619</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Good job Borparo! I had a similar thing happen to me, not only once, but twice! Always got to watch those texture or sprite dimensions! I'd love to see your game or some screen shots if you get a chance!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2018462</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2018462</link>
				<description></description>
				<pubDate>Thu, 24 Apr 2014 05:28:15 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hey guys,</p> <p>My most sincere apologies for this. The problem is in the texture itself. AS i was using the full Y dimensions of the paddle spriteSheet. So, if the paddle first frame, that i was using as static paddle, has an Y value of 100, i had in the code like the double, that corresponds to the full expand animation frame.</p> <p>Thanks a lot rbwhitaker. When you asked about how i was computing, took me a while, but i realized the texture values were wrong.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2018448</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2018448</link>
				<description></description>
				<pubDate>Thu, 24 Apr 2014 04:54:11 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi rbwhitaker,</p> <p>This is the code i have in the paddle class:</p> <div class="code"> <pre><code> public override void Update(GameTime gameTime, Rectangle clientBounds) { switch (Name) //enables paddles controls { case &quot;player1&quot;: { if (Keyboard.GetState().IsKeyDown(Keys.W)) this.position.Y -= Speed.Y; if (Keyboard.GetState().IsKeyDown(Keys.S)) position.Y += Speed.Y; break; } case &quot;player2&quot;: { if (Keyboard.GetState().IsKeyDown(Keys.Up)) position.Y -= Speed.Y; if (Keyboard.GetState().IsKeyDown(Keys.Down)) position.Y += Speed.Y; break; } case &quot;com&quot;: { //TODO MOVE PADDLE TO HIT BALL break; } } //keep Y position inside window boundaries position.Y = MathHelper.Clamp(Position.Y, 0, clientBounds.Height - texture.Height); }</code></pre></div> <p>then in the Game1 class i use it like this, inside the state for the playing game</p> <div class="code"> <pre><code> case GameState.playingGame: // output feedback Console.WriteLine(player1.Position); Console.WriteLine(mouseState.X + &quot;, &quot; + mouseState.Y); Console.WriteLine(Window.ClientBounds.Width); Console.WriteLine(Window.ClientBounds.Height); player1.Update(gameTime, Window.ClientBounds); player2.Update(gameTime, Window.ClientBounds); ball.Update(gameTime, Window.ClientBounds);</code></pre></div> <p>and here is where i'm confused. I expected with this to get the game window dimensions, however the bounds doesn't match :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2018158</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2018158</link>
				<description></description>
				<pubDate>Wed, 23 Apr 2014 19:59:54 +0000</pubDate>
				<wikidot:authorName>rbwhitaker</wikidot:authorName>				<wikidot:authorUserId>88099</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>How are you computing <em>clientBounds</em>? If there's a mismatch, it's going to do what you're describing.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2017728</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2017728</link>
				<description></description>
				<pubDate>Wed, 23 Apr 2014 07:21:50 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi rbwhitaker and PiscesMike,</p> <p>Thanks a lot for the help. At the moment, i got it working with an if /else statement in the Update method, that sets the length of the animation like this:</p> <div class="code"> <pre><code> if (collideP1()) { player1.SheetSize = new Point(6, 1); } else { player1.SheetSize = new Point(1, 1); }</code></pre></div> <p>it does the job without using animationActive, have to try rbwhitaker suggestion yet, so i consider it like a temporally solution until solve some problem i'm having with the ClientBounds, and would like to ask if you have experience something similar.<br /> I did the graphics for a 1600 x 1200 window resolution and added this lines in the Game1 constructor method:</p> <div class="code"> <pre><code> graphics.PreferredBackBufferWidth = 1600; graphics.PreferredBackBufferHeight = 1200;</code></pre></div> <p>However, the paddles and the ball seem to have a smaller resolution client bounds when running the game, as their bound limits in y top and bottom, doesn't reach the window ones.<br /> This is the expression i'm using to keep the paddles within the window:</p> <div class="code"> <pre><code>position.Y = MathHelper.Clamp(Position.Y, 0, clientBounds.Height - frameSize.Y);</code></pre></div> <p>hope i haven't make it to confusing.<br /> Thanks in advance.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2017494</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2017494</link>
				<description></description>
				<pubDate>Wed, 23 Apr 2014 00:06:23 +0000</pubDate>
				<wikidot:authorName>rbwhitaker</wikidot:authorName>				<wikidot:authorUserId>88099</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I think the problem you're having is that you're running the entire animation the instant it detects a collision, as opposed to letting it run across multiple updates. Your looping code seems correct at first glance, you just do the whole thing, stepping through each and every frame of the animation before the game has a chance to draw a frame to the screen.</p> <p>What I might suggest instead is that you rename your method to <em>BeginAnimation</em> and strip it down to just setting <em>animationActive</em> to <em>true</em>, and resetting <em>currentFrameX</em> and <em>currentFrameY</em> back to 0. (You're effectively resetting the animation to the starting point.)</p> <p>The rest of the loop gets moved to an <em>Update</em> method somewhere else (perhaps the <em>Update</em> method on your main Game class, but it would be better if the game object the animation it is associated with had an <em>Update</em> method of its own) and would get called each update cycle.</p> <p>Does that make sense?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2011342</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2011342</link>
				<description></description>
				<pubDate>Sat, 12 Apr 2014 17:56:33 +0000</pubDate>
				<wikidot:authorName>PiscesMike</wikidot:authorName>				<wikidot:authorUserId>1721619</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Cool, I hope it helps! If you have any questions, feel free to shoot them my way. That particular project was actually my first ever C# app so you might run across some things that could be done differently or more efficiently, or that just seems confusing. One things for instance, is that since I was writing all that code to be reusable as much as possible, I use a class to store all the basic XNA objects (graphics, gametime, spriteBatch, etc)&#8230; That way they can be shifted around to whichever class or methods needs them at the moment. One of the other quirky things I did was to create a statemanager which simply switches out the rendering process between different 'state' classes. It seems a little strange, but it basically allows me to encapsulate all the items that are needed for rendering whatever is going to the screen in it's own class and move between those 'states' as needed.<br /> I took a look at the code last night, and from what I was looking at, things seemed fairly well commented, but that might not always be the case. (I don't remember if I did actually comment everything).<br /> Good luck!</p> <p>Oh, and one last thing. If you're seeing a few frames pop up, but not the whole animation, it may be a timing issue with the frame. In the example code, I use a float to track the amount of time between gametime updates which allows me to make sure each frame is displayed for a certain amount of time. If there's no pause between frame updates, it may be cycling through the animation very very quickly, and you only see a few of the frames. Just a thought!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2011153</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2011153</link>
				<description></description>
				<pubDate>Sat, 12 Apr 2014 05:02:48 +0000</pubDate>
				<wikidot:authorName>borparo</wikidot:authorName>				<wikidot:authorUserId>1870868</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi PiscesMike,</p> <p>Yes, for detecting collision i'm using 2 rectangles in a boolean method:</p> <div class="code"> <pre><code> public bool collideP1() { Rectangle player1Rect = new Rectangle((int)player1.Position.X - player1.CollisionOffset, (int)player1.Position.Y - player1.CollisionOffset, player1.FrameSize.X - player1.CollisionOffset, player1.FrameSize.Y - player1.CollisionOffset); Rectangle ballRect = new Rectangle((int)ball.Position.X, (int)ball.Position.Y, ball.FrameSize.X, ball.FrameSize.Y); return ballRect.Intersects(player1Rect); }</code></pre></div> <p>Although in the code i managed to make it play as long the method is true, and every time the sprites collide i can see a few frames playing.</p> <p>I 'm going to take a look to the code in the link you sent me and try to find the answer :)</p> <p>thanks!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2010901</guid>
				<title>Re: Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2010901</link>
				<description></description>
				<pubDate>Fri, 11 Apr 2014 17:39:14 +0000</pubDate>
				<wikidot:authorName>PiscesMike</wikidot:authorName>				<wikidot:authorUserId>1721619</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Greetings Borja! I have looked through the code you posted, and assuming the sheetsize.x and sheetsize.y is correct, don't see a problem. It could be that the collisionP1() is somehow not being fired correctly. Are you by any chance using a RECT structure? I had a ton of problems getting that to work on my breakout game.<br /> Could you post the code for the collideP1()?</p> <p>In the meantime, I've made the entire code for my breakout project available to everyone here. It can be downloaded at:<br /> <a href="https://rapidshare.com/download/share/20966770DE4890408CD5A1B361D7F733">https://rapidshare.com/download/share/20966770DE4890408CD5A1B361D7F733</a></p> <p>In this project, I've made a number of classes to help with basic game building, so you might find some of it useful. Specifically, there is an AnimatedSprite class I use for animations which does work, so you may find an answer in there. Like I said, it seems kind of like the collision isn't firing. Have you set a breakpoint in the Animation class to make sure it is being called?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-843751#post-2010591</guid>
				<title>Playing animation just once.</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-843751/playing-animation-just-once#post-2010591</link>
				<description></description>
				<pubDate>Fri, 11 Apr 2014 05:31:59 +0000</pubDate>
				<wikidot:authorName>Borja Panadero</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Hello,</p> <p>I'm trying to recreate a PONG game and would like to animate (expand) the paddles vertically when the ball collides with them.<br /> I have a Sprite class with this Animate method:</p> <div class="code"> <pre><code>public void Animate() // start animation loop when ball collides { animationActive = true; // while bool is true play the sprite frames while (animationActive) { ++currentFrame.X; if (currentFrame.X &gt;= sheetSize.X) { currentFrame.X = 0; ++currentFrame.Y; if (currentFrame.Y &gt;= sheetSize.Y) { currentFrame.Y = 0; animationActive = false; } } } }</code></pre></div> <p>As you can imagine. My problem is the animation doesn't play when the ball hits the paddle.<br /> For checking the collision i have a collide method that i call in the Update() like this:</p> <div class="code"> <pre><code> if (collideP1()) player1.Animate();</code></pre></div> <p>Thanks for the help.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>