<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7363733076351225548</atom:id><lastBuildDate>Sun, 22 Mar 2026 12:22:23 +0000</lastBuildDate><title>Flatformer</title><description>Flatformer is a blog focusing on creating games, tech news, and numerous tutorials about the web. It&#39;s all right here.</description><link>http://flatformer.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7363733076351225548.post-4730821649020849204</guid><pubDate>Mon, 08 Mar 2010 05:15:00 +0000</pubDate><atom:updated>2010-03-07T21:18:47.335-08:00</atom:updated><title>Quick Tip: Temporarily hiding Intellisense Window</title><description>I&#39;m not sure if you&#39;ve ever had the event where you were typing code in Visual Studio/Express and the Intellisense window pops out and you can&#39;t see what&#39;s behind it. This happens to me when I sometimes forget the variable name of something, especially if I&#39;m in a loop at the time.&lt;br /&gt;
&lt;br /&gt;
Well, the solution is to simply press the control button. This works with both the left &lt;b&gt;and&lt;/b&gt;&amp;nbsp;right control buttons, in case you are curious. A screenshot of this in action is below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i45.tinypic.com/jfybfc.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i45.tinypic.com/jfybfc.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;i&gt;If you have any questions, comments, or concerns, remember to leave me a comment. If you enjoyed the post, remember to &lt;a href=&quot;http://flatformer.blogspot.com/&quot;&gt;Subscribe to my RSS feed.&lt;/a&gt;&lt;br /&gt;Or email me at finaiized(at)gmail.com if you want. I&#39;m welcome to all suggestions you may have, and am willing to help you.&lt;/i&gt;</description><link>http://flatformer.blogspot.com/2010/03/quick-tip-temporarily-hiding.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i45.tinypic.com/jfybfc_th.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7363733076351225548.post-8979482283103651101</guid><pubDate>Sun, 21 Feb 2010 22:43:00 +0000</pubDate><atom:updated>2010-03-07T21:31:52.354-08:00</atom:updated><title>Making a character jump in XNA/C# (Basic Concept Included)</title><description>In the &lt;a href=&quot;http://flatformer.blogspot.com/2010/02/simple-2d-gravity-in-games-explanation.html&quot;&gt;last tutorial&lt;/a&gt;, I briefly went over implementing gravity in games. By the end of the tutorial, we are going to program a character jumping when a key is pressed. I included &#39;Basic Concept Included&#39; in the title because it doesn&#39;t use any XNA/C# specific stuff, just some simple math.&lt;br /&gt;
&lt;h4&gt;




Jump?   &lt;/h4&gt;
Well, I&#39;ll first start off by telling you want happens in a &#39;jump&#39;. First, upward force is applied and the character moves up. Somewhere down the road, gravity acts on it and it moves down. &lt;br /&gt;
I’m going to define all the variables in one go:&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:dd5bcc2f-7a49-4ec8-81c8-491e762a90f2&quot; style=&quot;display: inline; float: none; margin: 0px; padding: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/*&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;GraphicsDeviceManager, SpriteBatch, Texture2D and Vector2 may be found only in XNA. They are just used for drawing objects and defining locations.&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;*/&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
GraphicsDeviceManager graphics; 
SpriteBatch spriteBatch;
Texture2D &lt;/span&gt;charr&lt;span style=&quot;color: black;&quot;&gt;;
Vector2 charPos;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; jumping; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Is the character jumping?&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; startY, jumpspeed &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;startY to tell us &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;where it lands, jumpspeed to see how fast it jumps&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Now, to the Initialize() function, provided by XNA:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2936781a-9ee5-41d1-8b87-0a9fe5beb10b&quot; style=&quot;display: inline; float: none; margin: 0px; padding: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;charr &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; Content.Load&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Texture2D&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;ow&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Load image&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;charPos &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; Vector2(&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;230&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;450&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Char loc, X/Y&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;startY &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; charPos.Y;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Starting position&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;jumping &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Init jumping to false&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;jumpspeed &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Default no speed&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
And the Update(), where the following is updated every frame:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:86ad99e0-2c35-401e-8e76-a54010295732&quot; style=&quot;display: inline; float: none; margin: 0px; padding: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Init keyboard&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;KeyboardState keyState &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; Keyboard.GetState();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (jumping)
{
    charPos.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; jumpspeed;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Making it go up&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;    jumpspeed &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Some math (explained later)&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (charPos.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; startY)
        &lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;If it&#39;s farther than ground&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;        {
            charPos.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; startY;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Then set it on&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;               jumping &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;
        }
    }&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
{
    &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (keyState.IsKeyDown(Keys.Space)) 
    {
        jumping &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;
        jumpspeed &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Give it upward thrust&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
We can now draw it with spriteBatch:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:126477e1-3dcf-442f-92fe-dcfc2a861eea&quot; style=&quot;display: inline; float: none; margin: 0px; padding: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;spriteBatch.Begin();
spriteBatch.Draw(charr, charPos, Color.White);
spriteBatch.End();&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4&gt;




Explanation&lt;/h4&gt;
We update charPos’s Y axis by jumpspeed. Since jumpspeed is set to –14 when space is pressed, this makes it go up (or down, depends on the game engine/platform you are using). Now, the magic- by adding 1 to jumpspeed every frame after, it will turn positive after a while and move down instead!&lt;br /&gt;
The value of jumpspeed will look like this:&lt;br /&gt;
&lt;br /&gt;
-14,-13,-12….0,1,2,3….&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;If you have any questions, comments, or concerns, remember to leave me a comment. If you enjoyed the post, remember to &lt;a href=&quot;http://feeds2.feedburner.com/flatformer&quot; target=&quot;_blank&quot; title=&quot;Subscribe to my RSS feed&quot;&gt;Subscribe to my RSS feed.&lt;/a&gt;
Or email me at finaiized(at)gmail.com if you want. I&#39;m welcome to all suggestions you may have, and am willing to help you.&lt;/i&gt;</description><link>http://flatformer.blogspot.com/2010/02/making-character-jump-in-xnac-basic.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>30</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7363733076351225548.post-9087758057879026891</guid><pubDate>Sun, 21 Feb 2010 01:20:00 +0000</pubDate><atom:updated>2010-03-07T21:19:43.613-08:00</atom:updated><title>Simple 2D Gravity In Games [Explanation]</title><description>&lt;h4&gt;
Introduction&lt;/h4&gt;
Sometimes understanding gravity can be hard.   &lt;br /&gt;
I mean, yeah, it&#39;s always around us, it&#39;s always been there. But when trying to fake gravity into games- platformers is my example- it can sometimes get confusing. After this article, I hope you&#39;ll know how to implement gravity in any language- and since gravity is basically math, I&#39;m not going to recommend a particular programming language you should use to write it.   &lt;br /&gt;
&lt;br /&gt;
What&#39;s better to start than pull up a definition of gravity? So here&#39;s one, located &lt;a href=&quot;http://encarta.msn.com/dictionary_1861615141/gravity.html&quot;&gt;here&lt;/a&gt;:   &lt;br /&gt;
&lt;blockquote&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: tahoma;&quot;&gt;&lt;span class=&quot;ResultBodyBlack&quot; style=&quot;color: black; font-family: &#39;MS Reference Sans Serif&#39;, &#39;MSRef SS EOT&#39;, verdana, arial; font-size: 14px; font-weight: bold;&quot;&gt;&lt;b&gt;gravitational force: &lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;ResultBody&quot; style=&quot;color: #333333; font-family: &#39;MS Reference Sans Serif&#39;, &#39;MSRef SS EOT&#39;, verdana, arial; font-size: 14px; font-weight: normal;&quot;&gt;the attraction due to gravitation that the Earth or another astronomical object exerts on an object on or near its surface&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
We obviously don&#39;t have &#39;Earth&#39; in our game per say, but we know it has to do with &lt;i&gt;attraction&lt;/i&gt;. Let&#39;s keep this in mind and move on.   &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i46.tinypic.com/xctbw1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;192&quot; src=&quot;http://i46.tinypic.com/xctbw1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
(I know the image sucks). Above is a basic representation of gravity. Something is forced up, and gravity acts on it and it moves down gradually. How do we represent this change using math? Well, we’ll need to define gravity of course…&lt;/div&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;MS Reference Sans Serif&#39;, &#39;MSRef SS EOT&#39;, verdana, arial; font-size: 14px; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;  &lt;br /&gt;
&lt;h4&gt;
To the basics&lt;/h4&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;MS Reference Sans Serif&#39;, &#39;MSRef SS EOT&#39;, verdana, arial; font-size: 14px; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;I&#39;m going to start be representing super-basic gravity. We&#39;ll draw an image and make it move down at an increasingly fast pace, just like in real life.&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9241ce23-4ff7-46b3-92b7-c665c70b8b34&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: -pre-wrap; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;Declare gravity and add it to character&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; gravity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0.1f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;
character.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; gravity;
&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;To make it drop increasingly fast&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;gravity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0.1f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: -pre-wrap; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
Now that we&#39;ve done that, we can study the code. I first declare gravity, and assign it as 0.1 (the&lt;em&gt; f&lt;/em&gt; is to show it&#39;s a float/decimal number, depends on the programming language). Next, I add gravity to the character&#39;s &lt;em&gt;Y&lt;/em&gt; position (note here that sometimes you might have to subtract &lt;em&gt;y &lt;/em&gt;to make it go down) and finally increase gravity so it keeps falling faster. A lot of games I notice actually don&#39;t have this feature, and it all comes down to the matter of what you want.&lt;br /&gt;
&lt;h4&gt;
Limiting Gravity&lt;/h4&gt;
The example above is good and all, but it drops increasingly fast until it&#39;s &lt;i&gt;wayyy&lt;/i&gt; too fast. I&#39;m going to fix that by simply adding a check:&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:018bd1f7-7707-40b6-8f4b-f7c3f290c159&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: -pre-wrap; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (gravity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0.4f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) {
gravity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0.4f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;; 
}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
There we have it. Super basic gravity.&lt;br /&gt;
&lt;h4&gt;
Using Velocity&lt;/h4&gt;
I’m going to use velocity in the following examples. Velocity is the rate of change in the position of an object as it moves in a particular direction. We can use velocity coupled with gravity so we can actually travel in an ark- as it can take account of the current direction and add gravity on top of that.&lt;br /&gt;
&lt;br /&gt;
Here’s some code showing that:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:13c611cb-8bd3-4aac-9768-4972b2acc96b&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;pre style=&quot;background-color: white; overflow: auto; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: -pre-wrap; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Vector2 velocity;
&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; gravity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;0.1f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;

&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (keyPressed&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Keys.Right) {
velocity &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;3.0f&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;
}
velocity.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; gravity;
mainChar.X &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; velocity.X;
mainChar.Y &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; velocity.Y;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
Basically what I am doing here is creating a &lt;strong&gt;vector &lt;/strong&gt;(this is basically a multi-dimensional array, can be replaced by two float/decimals) and, responding to key presses, adding the velocity to the main character’s X and Y. By doing this, I can set multiple velocity increases and have it all affect the character similarly. Now I can easily code things like springs.&lt;br /&gt;
&lt;h4&gt;
Conclusion&lt;/h4&gt;
Here concludes my gravity tutorial. &lt;s&gt;I’ll be writing a tutorial on jumping next!&lt;/s&gt;&amp;nbsp;&lt;a href=&quot;http://flatformer.blogspot.com/2010/02/making-character-jump-in-xnac-basic.html&quot;&gt;It&#39;s up!&lt;/a&gt;
&lt;i&gt;If you have any questions, comments, or concerns, remember to leave me a comment. If you enjoyed the post, remember to &lt;a href=&quot;http://feeds2.feedburner.com/flatformer&quot; title=&quot;Subscribe to my RSS feed&quot; target=&quot;_blank&quot;&gt;Subscribe to my RSS feed.&lt;/a&gt;
Or email me at finaiized(at)gmail.com if you want. I&#39;m welcome to all suggestions you may have, and am willing to help you.&lt;/i&gt;</description><link>http://flatformer.blogspot.com/2010/02/simple-2d-gravity-in-games-explanation.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i46.tinypic.com/xctbw1_th.png" height="72" width="72"/><thr:total>40</thr:total></item></channel></rss>