<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://miniscript.org/w/index.php?action=history&amp;feed=atom&amp;title=How_to_move_a_sprite_forward</id>
	<title>How to move a sprite forward - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://miniscript.org/w/index.php?action=history&amp;feed=atom&amp;title=How_to_move_a_sprite_forward"/>
	<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;action=history"/>
	<updated>2026-04-23T15:09:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=832&amp;oldid=prev</id>
		<title>SebNozzi at 20:01, 20 November 2021</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=832&amp;oldid=prev"/>
		<updated>2021-11-20T20:01:35Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 20:01, 20 November 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Move a sprite in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the [[cos]] and [[sin]] functions, as shown below.  Note that [[cos]] and [[sin]] require an angle in radians, while [[Sprite.rotation]] is in degrees.  Convert from degrees to radians by multiplying by [[pi]]/180.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Move a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[[Sprite|&lt;/ins&gt;sprite&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;]] &lt;/ins&gt;in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the [[cos]] and [[sin]] functions, as shown below.  Note that [[cos]] and [[sin]] require an angle in radians, while [[Sprite.rotation]] is in degrees.  Convert from degrees to radians by multiplying by [[pi]]/180.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If &amp;quot;forward&amp;quot; for your sprite is not oriented to the right in the unrotated sprite image, then simply add some constant (e.g. 90) to the sprite rotation before converting to degrees.  The same can be done to make a sprite move left or right relative to whatever way it is facing.  To move backwards, you could either add 180 degrees, or simply use a negative speed.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If &amp;quot;forward&amp;quot; for your sprite is not oriented to the right in the unrotated sprite image, then simply add some constant (e.g. 90) to the sprite rotation before converting to degrees.  The same can be done to make a sprite move left or right relative to whatever way it is facing.  To move backwards, you could either add 180 degrees, or simply use a negative speed.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>SebNozzi</name></author>
		
	</entry>
	<entry>
		<id>http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=105&amp;oldid=prev</id>
		<title>JoeStrout at 13:58, 6 March 2020</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=105&amp;oldid=prev"/>
		<updated>2020-03-06T13:58:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:58, 6 March 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Move a sprite in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the [[cos]] and [[sin]] functions, as shown below.  Note that [[cos]] and [[sin]] require an angle in radians, while [[Sprite.rotation]] is in degrees.  Convert from degrees to radians by multiplying by [[pi]]/180.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Move a sprite in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the [[cos]] and [[sin]] functions, as shown below.  Note that [[cos]] and [[sin]] require an angle in radians, while [[Sprite.rotation]] is in degrees.  Convert from degrees to radians by multiplying by [[pi]]/180.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;If &amp;quot;forward&amp;quot; for your sprite is not oriented to the right in the unrotated sprite image, then simply add some constant (e.g. 90) to the sprite rotation before converting to degrees.  The same can be done to make a sprite move left or right relative to whatever way it is facing.  To move backwards, you could either add 180 degrees, or simply use a negative speed.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Example ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Example ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>JoeStrout</name></author>
		
	</entry>
	<entry>
		<id>http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=104&amp;oldid=prev</id>
		<title>JoeStrout: Created page with &quot;Move a sprite in its &quot;forward&quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the cos and sin functions, as shown below.  Note that cos...&quot;</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=How_to_move_a_sprite_forward&amp;diff=104&amp;oldid=prev"/>
		<updated>2020-03-06T13:56:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Move a sprite in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the &lt;a href=&quot;/wiki/Cos&quot; title=&quot;Cos&quot;&gt;cos&lt;/a&gt; and &lt;a href=&quot;/wiki/Sin&quot; title=&quot;Sin&quot;&gt;sin&lt;/a&gt; functions, as shown below.  Note that cos...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Move a sprite in its &amp;quot;forward&amp;quot; direction (i.e. in the +X direction when the sprite is not rotated) by using the [[cos]] and [[sin]] functions, as shown below.  Note that [[cos]] and [[sin]] require an angle in radians, while [[Sprite.rotation]] is in degrees.  Convert from degrees to radians by multiplying by [[pi]]/180.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This example moves a sprite in its forward direction, now and then changing to a new random direction.  (If the sprite wanders off the screen, just press Control-C to stop the program, and run again.)&lt;br /&gt;
&lt;br /&gt;
This could be combined with [[How to point a sprite at a target]] to make the sprite chase a target (such as the mouse).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ms&amp;gt;clear&lt;br /&gt;
sp = new Sprite&lt;br /&gt;
sp.image = file.loadImage(&amp;quot;/sys/pics/arrows/arrow2.png&amp;quot;)&lt;br /&gt;
sp.x = 300&lt;br /&gt;
sp.y = 320&lt;br /&gt;
display(4).sprites.push sp&lt;br /&gt;
speed = 2   // (pixels per frame)&lt;br /&gt;
while true // (press Control-C to exit)&lt;br /&gt;
	if rnd &amp;lt; 0.01 then sp.rotation = 360*rnd&lt;br /&gt;
	ang = sp.rotation * pi/180&lt;br /&gt;
	sp.x = sp.x + cos(ang) * speed&lt;br /&gt;
	sp.y = sp.y + sin(ang) * speed&lt;br /&gt;
	yield&lt;br /&gt;
end while&amp;lt;/ms&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Mini Micro]]&lt;br /&gt;
[[Category:How To]]&lt;/div&gt;</summary>
		<author><name>JoeStrout</name></author>
		
	</entry>
</feed>