SpriteLibrary/SpriteLibrary/Doc/Help/html/07a473e4-4716-e5b9-c7d2-c47...

210 lines
42 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="X-UA-Compatible" content="IE=edge" /><link rel="shortcut icon" href="../icons/favicon.ico" /><link rel="stylesheet" type="text/css" href="../styles/branding.css" /><link rel="stylesheet" type="text/css" href="../styles/branding-en-US.css" /><script type="text/javascript" src="../scripts/branding.js"> </script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>SpriteController Class</title><meta name="Language" content="en-us" /><meta name="System.Keywords" content="SpriteController class" /><meta name="System.Keywords" content="SpriteLibrary.SpriteController class" /><meta name="System.Keywords" content="SpriteController class, about SpriteController class" /><meta name="Microsoft.Help.F1" content="SpriteLibrary.SpriteController" /><meta name="Microsoft.Help.Id" content="T:SpriteLibrary.SpriteController" /><meta name="Description" content="A sprite controller is the main heart of the sprite class. Each SpriteController manages one picturebox." /><meta name="Microsoft.Help.ContentType" content="Reference" /><meta name="BrandingAware" content="true" /><meta name="container" content="SpriteLibrary" /><meta name="file" content="07a473e4-4716-e5b9-c7d2-c4748265fc58" /><meta name="guid" content="07a473e4-4716-e5b9-c7d2-c4748265fc58" /><link type="text/css" rel="stylesheet" href="../styles/highlight.css" /><script type="text/javascript" src="../scripts/highlight.js"> </script><link rel="stylesheet" type="text/css" href="../styles/branding-Website.css" /><script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script><script type="text/javascript" src="../scripts/branding-Website.js"></script><script type="text/javascript" src="../scripts/clipboard.min.js"></script></head><body onload="OnLoad('cs')"><input type="hidden" id="userDataCache" class="userDataStyle" /><div class="pageHeader" id="PageHeader">SpriteLibrary<form id="SearchForm" method="get" action="#" onsubmit="javascript:TransferToSearchPage(); return false;"><input id="SearchTextBox" type="text" maxlength="200" /><button id="SearchButton" type="submit"></button></form></div><div class="pageBody"><div class="leftNav" id="leftNav"><div id="tocNav"><div class="toclevel0" data-toclevel="0"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="6b7227c0-7a6a-6342-3b08-917c7de429cc.htm" title="SpriteLibrary" tocid="roottoc">SpriteLibrary</a></div><div class="toclevel0" data-toclevel="0"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="6b7227c0-7a6a-6342-3b08-917c7de429cc.htm" title="SpriteLibrary" tocid="6b7227c0-7a6a-6342-3b08-917c7de429cc">SpriteLibrary</a></div><div class="toclevel1 current" data-toclevel="1" data-childrenloaded="true"><a class="tocExpanded" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="07a473e4-4716-e5b9-c7d2-c4748265fc58.htm" title="SpriteController Class" tocid="07a473e4-4716-e5b9-c7d2-c4748265fc58">SpriteController Class</a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="323c4f03-703d-0898-c73e-40eb5784c05f.htm" title="SpriteController Constructor " tocid="323c4f03-703d-0898-c73e-40eb5784c05f">SpriteController Constructor </a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="c6c542de-2b1f-1086-b5b2-56b7e9a9525f.htm" title="SpriteController Properties" tocid="c6c542de-2b1f-1086-b5b2-56b7e9a9525f">SpriteController Properties</a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="2788d4d5-88bf-1154-dd17-8d4b99a79118.htm" title="SpriteController Methods" tocid="2788d4d5-88bf-1154-dd17-8d4b99a79118">SpriteController Methods</a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="4141394a-0d7d-5cf8-6b01-0a4fb43159ab.htm" title="SpriteController Events" tocid="4141394a-0d7d-5cf8-6b01-0a4fb43159ab">SpriteController Events</a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="92b04460-74f1-c388-f3ac-ea510ffc4e06.htm" title="SpriteController Fields" tocid="92b04460-74f1-c388-f3ac-ea510ffc4e06">SpriteController Fields</a></div></div><div id="tocResizableEW" onmousedown="OnMouseDown(event);"></div><div id="TocResize" class="tocResize"><img id="ResizeImageIncrease" src="../icons/TocOpen.gif" onclick="OnIncreaseToc()" alt="Click or drag to resize" title="Click or drag to resize" /><img id="ResizeImageReset" src="../icons/TocClose.gif" style="display:none" onclick="OnResetToc()" alt="Click or drag to resize" title="Click or drag to resize" /></div></div><div class="topicContent" id="TopicContent"><table class="titleTable"><tr><td class="titleColumn">SpriteController Class</td></tr></table><span class="introStyle"></span> <div class="summary">
A sprite controller is the main heart of the sprite class. Each SpriteController manages one picturebox.
If at all possible, try to keep each game in one picturebox, and try to avoid making and destroying
new forms with SpriteController/pictureboxes in them. It is hard to destroy them completely.
</div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID0RB')" onkeypress="SectionExpandCollapse_CheckKey('ID0RB', event)" tabindex="0"><img id="ID0RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Inheritance Hierarchy</span></div><div id="ID0RBSection" class="collapsibleSection"><a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">System<span id="LSTA876BB2B_0"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTA876BB2B_0?cs=.|vb=.|cpp=::|nu=.|fs=.");</script>Object</a><br />  <span class="selflink">SpriteLibrary<span id="LSTA876BB2B_1"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTA876BB2B_1?cs=.|vb=.|cpp=::|nu=.|fs=.");</script>SpriteController</span><br /></div><p> </p>
<strong>Namespace:</strong>
 <a href="6b7227c0-7a6a-6342-3b08-917c7de429cc.htm">SpriteLibrary</a><br />
<strong>Assembly:</strong>
 SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.5 (1.0.0.5)<div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID2RB')" onkeypress="SectionExpandCollapse_CheckKey('ID2RB', event)" tabindex="0"><img id="ID2RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Syntax</span></div><div id="ID2RBSection" class="collapsibleSection"><div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID1EACA_tab1" class="codeSnippetContainerTabSingle">C#</div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID1EACA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID1EACA');return false;" title="Copy">Copy</a></div></div><div id="ID1EACA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="keyword">public</span> <span class="keyword">class</span> <span class="identifier">SpriteController</span></pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID1EACA");</script></div><p>The <span class="selflink">SpriteController</span> type exposes the following members.</p><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID3RB')" onkeypress="SectionExpandCollapse_CheckKey('ID3RB', event)" tabindex="0"><img id="ID3RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Constructors</span></div><div id="ID3RBSection" class="collapsibleSection"><table class="members" id="constructorList"><tr><th class="iconColumn">
 
</th><th>Name</th><th>Description</th></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="dd581cb5-2630-cc79-5fcb-24bfcb817e03.htm">SpriteController(PictureBox)</a></td><td><div class="summary">
Create a sprite controller, specifying the picturebox on which the sprites
will be displayed. You want to have the PictureBox already defined, and a background image
already set for the PictureBox.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="d20e5816-faf3-723d-5f2d-ebff462012f1.htm">SpriteController(PictureBox, EventHandler)</a></td><td><div class="summary">
Create a sprite controller, specifying the picturebox on which the sprites
will be displayed.
</div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID4RB')" onkeypress="SectionExpandCollapse_CheckKey('ID4RB', event)" tabindex="0"><img id="ID4RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Properties</span></div><div id="ID4RBSection" class="collapsibleSection"><table class="members" id="propertyList"><tr><th class="iconColumn">
 
</th><th>Name</th><th>Description</th></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubproperty.gif" alt="Public property" title="Public property" /></td><td><a href="9d9cf5a5-3349-bfae-7d39-41082644a49e.htm">BackgroundImage</a></td><td><div class="summary">
The Background Image on which the sprites are drawn. This image ends up having
sprite parts on it. The OriginalImage is the version that is clean. Use
ReplaceOriginalImage to replace the background Image.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubproperty.gif" alt="Public property" title="Public property" /></td><td><a href="7d3a40d7-0ee8-6117-8d32-b236da97778f.htm">OriginalImage</a></td><td><div class="summary">
The Image from which the background is taken when we erase sprites. The BackgroundImage
is the image that contains images of the sprites as well as the background image. Use
ReplaceOriginalImage to replace this and the BackgroundImage.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubproperty.gif" alt="Public property" title="Public property" /></td><td><a href="6e7ddbc9-4f71-533f-b99c-55a53ba4a843.htm">SpriteCount</a></td><td><div class="summary">
The count of all the sprites the controller knows about. This includes named
sprites, which may not be visible.
</div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID6RB')" onkeypress="SectionExpandCollapse_CheckKey('ID6RB', event)" tabindex="0"><img id="ID6RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Methods</span></div><div id="ID6RBSection" class="collapsibleSection"><table class="members" id="methodList"><tr><th class="iconColumn">
 
</th><th>Name</th><th>Description</th></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="f28be11d-b67a-765c-441a-d7da336ccf77.htm">AddSprite</a></td><td><div class="summary">
Add the specified sprite to the list of sprites we know about. You usually do not need to do this.
Sprites add themselves to the controller when you create a new sprite.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="68ba53c6-5c0d-3dd4-b9bd-56852a3b98cd.htm">AdjustPoint</a></td><td><div class="summary">
Adjust an image point so that it conforms to the picturebox.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="4f100dc3-39b4-fea4-6d73-8ef39eea489c.htm">AdjustRectangle</a></td><td><div class="summary">
Adjust a rectangle that is based on the image, according to the stretch of the picturebox
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="662ea0d6-7a35-be51-5a25-288752509d24.htm">AllSprites</a></td><td><div class="summary">
Return a list of all sprites
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="bf55ab7f-78c8-3879-b8f8-464dc203791e.htm">ChangeTickInterval</a></td><td><div class="summary">
Change the Tick Interval. By default, the spritecontroller does a tick every 10ms, which
is very fast. Some people may prefer it to happen less regularly. Must be &gt; 5, and less than 1001
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="dace8c3a-8d35-4ae7-ddf8-26e59dc161ae.htm">CountSpritesBasedOff</a></td><td><div class="summary">
Count the number of sprites that were duplicated from the sprite with the specified name. When you use a
<a href="60fe71db-5ea2-cf93-f216-79b15a6779db.htm">SpriteController.DuplicateSprite(string)</a>
command, it creates a new sprite that is based off the named sprite. This function will count those duplicated sprites.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="63fd5f6f-f592-0dbd-6fd2-ff4b999f012d.htm">DestroyAllSprites</a></td><td><div class="summary">
Remove all sprites (even named sprites that have not yet been displayed)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="56b507fc-3071-20e9-63a7-b33484f3e687.htm">DestroySprite</a></td><td><div class="summary">
Tell a sprite to destroy itself. The sprite will have Destroying property set to true from
the time you destroy it until it vanishes. Whe you destroy a sprite, it will erase itself
and remove itself from the controller. After it is destroyed, it is completely gone.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="60fe71db-5ea2-cf93-f216-79b15a6779db.htm">DuplicateSprite(String)</a></td><td><div class="summary">
Find a sprite that has been named with the specified name. Then duplicate that sprite
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="ef714268-ae13-47ad-c8a8-1b8bb39cfed9.htm">DuplicateSprite(Sprite)</a></td><td><div class="summary">
Make a duplicate of the specified sprite. The duplicate does not yet have a location.
</div></td></tr><tr data="public;inherited;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/bsc2ak47" target="_blank">Equals</a></td><td><div class="summary">Determines whether the specified object is equal to the current object.</div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="protected;inherited;notNetfw;"><td><img src="../icons/protmethod.gif" alt="Protected method" title="Protected method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/4k87zsw7" target="_blank">Finalize</a></td><td><div class="summary">Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.</div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="public;inherited;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/zdee4b3y" target="_blank">GetHashCode</a></td><td><div class="summary">Serves as the default hash function. </div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="public;inherited;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/dfwy45w9" target="_blank">GetType</a></td><td><div class="summary">Gets the <a href="http://msdn2.microsoft.com/en-us/library/42892f65" target="_blank">Type</a> of the current instance.</div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="451487c4-0cca-2c80-9b71-b116cbe00d6e.htm">Invalidate(Boolean)</a></td><td><div class="summary">
Invalidate the entire image on which the sprites are drawn
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="c57680f5-fd0e-a4a6-05a0-3a42de94edb8.htm">Invalidate(Rectangle, Boolean)</a></td><td><div class="summary">
Invalidate a rectangle that is specified in image coordinates
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="bf10cc41-d9e2-52c5-0415-1083f0f55489.htm">IsKeyPressed<span id="LSTA876BB2B_2"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTA876BB2B_2?cs=()|vb=|cpp=()|nu=()|fs=()");</script></a></td><td><div class="summary">
Check to see if any keys are pressed. There is a small glitch with the
key-pressed system. If the form loses focus, and someone releases a key, the key-up is never
triggered. It is a good thing to ResetKeypressState() occasionally if you think your form may have
lost focus.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="7fc92c27-7895-2b2c-d4f1-ac682eec7af5.htm">IsKeyPressed(Keys)</a></td><td><div class="summary">
Check to see if the given key is pressed. There is a small glitch with the
key-pressed system. If the form loses focus, and someone releases a key, the key-up is never
triggered. It is a good thing to ResetKeypressState() occasionally if you think your form may have
lost focus.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="bcb29da5-8d8d-fa11-90ea-3a0cc73a0df0.htm">KeysPressed</a></td><td><div class="summary">
Return a list of all the keys that are currently pressed. There is a small glitch with the
key-pressed system. If the form loses focus, and someone releases a key, the key-up is never
triggered. It is a good thing to ResetKeypressState() occasionally if you think your form may have
lost focus.
</div></td></tr><tr data="protected;inherited;notNetfw;"><td><img src="../icons/protmethod.gif" alt="Protected method" title="Protected method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/57ctke0a" target="_blank">MemberwiseClone</a></td><td><div class="summary">Creates a shallow copy of the current <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.</div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="a5292253-7fbd-5dfa-819f-1d67d27580d6.htm">NameSprite</a></td><td><div class="summary">
Find the specified Sprite in the controller and change its name to the specified string.
You can do the same thing with <a href="36d40ecf-484f-3b53-43e4-87ed9108cb76.htm">Sprite.SetName(Name)</a></div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="d329fe20-e750-bf52-a75b-f2383bf1d35a.htm">Pause</a></td><td><div class="summary">
Pause everything. It loops through all the sprites in the SpriteController and sends the specified
SpritePauseType to each one. Look at the documentation for SpritePauseType to determine which pause
type to use.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="0b27d26e-53e1-c9bd-0b52-8fe4714c831a.htm">PlaceSpriteBehind</a></td><td><div class="summary">
Change the display order of the sprites such that the specified sprite appears behind the other sprite.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="8d47a519-d5f7-c7f6-4ccb-0d310cab2435.htm">PlaceSpriteInFrontOf</a></td><td><div class="summary">
Make the sprite go in front of the specified sprite.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="af7fceb3-a35e-b016-3955-696b3a3c7a7e.htm">RegisterKeyDownFunction</a></td><td><div class="summary">
If you want to have a KeyDown function that is triggered by a keypress function, add the event here.
The event should have the parameters (object sender, KeyEventArgs e)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="b3e934e2-1ddf-35e3-0995-3b555539f33f.htm">RegisterKeyUpFunction</a></td><td><div class="summary">
If you want to have a KeyUp function that is triggered by a keypress function, add the event here.
The event should have the parameters (object sender, KeyEventArgs e)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="49befa66-d9d0-400c-1fc2-ac57f17433f1.htm">ReplaceOriginalImage<span id="LSTA876BB2B_3"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTA876BB2B_3?cs=()|vb=|cpp=()|nu=()|fs=()");</script></a></td><td><div class="summary">
Notify the sprite controller that you have changed the background image on the
PictureBox. Whatever background is on the picturebox is now used to draw all the sprites on.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="eac30137-8237-e01a-ee3d-e599d117c03e.htm">ReplaceOriginalImage(Image)</a></td><td><div class="summary">
Replace the image on which the sprites are drawn. Use this when you move to a new playing field,
or want to have a different background
<div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID5RB')" onkeypress="SectionExpandCollapse_CheckKey('ID5RB', event)" tabindex="0"><img id="ID5RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Examples</span></div><div id="ID5RBSection" class="collapsibleSection">
Replacing the background image is actually a lot more complex than you might imagine. Once you use the
below code, it can be done without any problem. But you need to do it this way, or it just goofs up in
a number of small ways.
You need to tell the sprite controller that you are replacing the background image,
and you need to change the image to that image as well.Because the Images are actually
pointers to memory where the image sets, changes to one image will affect the other image.This goofs
things up, so what we do is duplicate the image twice, and tell the sprite controller to use one of the
copies and then set the background to be the other one of the two copies.Finally, we tell the picturebox
to invalidate itself.That does everything that is needed.
<div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID1EAAAAEWCDA_tab1" class="codeSnippetContainerTabSingle">C#</div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID1EAAAAEWCDA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID1EAAAAEWCDA');return false;" title="Copy">Copy</a></div></div><div id="ID1EAAAAEWCDA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve"> <span class="highlight-keyword">void</span> ReplaceBackground(Image NewBackground)
{
<span class="highlight-keyword">if</span> (MyController == <span class="highlight-keyword">null</span>) <span class="highlight-keyword">return</span>;
<span class="highlight-keyword">if</span> (NewBackground == <span class="highlight-keyword">null</span>) <span class="highlight-keyword">return</span>;
Image OneImage = <span class="highlight-keyword">new</span> Bitmap(NewBackground);
MyController.ReplaceOriginalImage(OneImage);
Image TwoImage = <span class="highlight-keyword">new</span> Bitmap(NewBackground);
pb_map.BackgroundImage = TwoImage;
pb_map.Invalidate();
}</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID1EAAAAEWCDA");</script></div></div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="48ff9be7-1395-25af-3585-3d32eba07309.htm">ResetKeypressState</a></td><td><div class="summary">
Reset the keypress status. Sometimes the sprite controller misses a key being released (usually
because a window has taken priority, or something has changed). Calling this function will reset
the stored memory of whether a key has been pressed.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="41ac663a-2019-6a14-5ffd-16dfc7472578.htm">ReturnAdjustmentRatio</a></td><td><div class="summary">
Return an adjustment ratio. This is the image-size to picture-box ratio.
It is used for calculating precise pixels or picture-box locations.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="447d1a9a-0e17-9827-2a01-438434c1b879.htm">ReturnPictureBoxAdjustedHeight</a></td><td><div class="summary">
Return the height of an object in picture-box terms. It is basically the virtual height
of the sprite or other item.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="9469b7cf-55ee-5c2e-feb7-01c7e23a6350.htm">ReturnPictureBoxAdjustedPoint</a></td><td><div class="summary">
This does the reverse of an adjusted point. It takes a point on the image and
transforms it to one on the PictureBox
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="7c73b68e-f842-bfee-55d8-b36488fb35b7.htm">ReturnPictureBoxAdjustedWidth</a></td><td><div class="summary">
Return the width of an object in picture-box terms. It takes the width of a sprite or other
item that is being displayed on the screen, and calculates the width as displayed in the
picture-box (taking into consideration stretching or shrinking)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="e58bfa3c-4722-7f3a-9610-0a0ce62bfe99.htm">ReturnPointAdjustedForImage</a></td><td><div class="summary">
This takes a point, the location on a picturebox, and returns the corresponding point on the BackgroundImage.
Picturebox locations are "sloppy"; the background image locations are very precise. Since this takes a "sloppy"
number and returns a precise number, it does some rounding to figure out where the specified location is.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="df0fd1e8-eac8-4f10-7f09-baa6127f3752.htm">SoundIsFinished</a></td><td><div class="summary">
Check to see if the specified sound has finished playing
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="08442d70-3a79-fa24-4f3e-eddc5c102938.htm">SoundPlay</a></td><td><div class="summary">
Play a sound that we can check to see if it has completed.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="d516c33b-29ef-9613-62fb-b6717264a32b.htm">SpriteBackwards</a></td><td><div class="summary">
Change the display order of the specified sprite so it is more likely to go behind all other sprites.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="b5c75d58-f132-f3ff-217f-e69b252db748.htm">SpriteForwards</a></td><td><div class="summary">
Change the display order of the specified sprite so it is more likely to go in front of other sprites
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="e8491570-1fda-7d8e-48b8-c15f26c41d01.htm">SpriteFromName</a></td><td><div class="summary">
Find a sprite that has a specified name. This returns the actual sprite with that name.
You usually want to use DuplicateSprite(Name) to clone the sprite and get one you can
destroy. If you destroy a named sprite without duplicating it, you may end up losing
it for the remainder of the program.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="90511f90-497b-fc61-6984-15d76101a6f1.htm">SpritesAtImagePoint</a></td><td><div class="summary">
This takes a point, as as specified on the image, and returns the sprites at that point. Different
functions use different coordinates, whether based off the background image, or based off the picturebox.
This one uses the background image coordinates. Use SpritesAdPoint() if you are doing something based off
a MouseUp or MouseDown function. This is used for functions based on sprite location or based off the absoloute
location (using the background image location is much more precise than the visible location in the picturebox)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="3c18bbb7-e10c-1b96-754d-7dfc878e7cf4.htm">SpritesAtPoint</a></td><td><div class="summary">
This takes a point, as given by the mouse-click args, and returns the sprites at that point. Different
functions use different coordinates, whether based off the background image, or based off the picturebox.
This one uses the picturebox coordinates. So you can use this directly from a MouseDown or MouseUp function.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="e05efb85-3736-fa59-2720-a460b898048a.htm">SpritesBasedOff</a></td><td><div class="summary">
Return all sprites that were based off a particular sprite name.
When you use a
<a href="60fe71db-5ea2-cf93-f216-79b15a6779db.htm">SpriteController.DuplicateSprite(string)</a>
command, it creates a new sprite that is based off the named sprite. This function returns a list of those
duplicated sprites.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="c7991a63-f63c-20d8-0605-fab6e9f13392.htm">SpritesBasedOffAnything</a></td><td><div class="summary">
Return a list of all sprites which are not master sprites (which are duplicates of something)
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="c2860c42-fc4c-78f8-7d32-195e74262434.htm">SpritesInImageRectangle</a></td><td><div class="summary">
Return a list of all the sprites that intersect with the given background-image-based rectangle
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="2c4eb5db-5c4c-6fcd-716c-532c0e2c4f35.htm">SpritesThatHaveBeenDrawn</a></td><td><div class="summary">
Return a list of all sprites which have been drawn on the image
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="5d32e0da-bbf2-10b5-ba20-fe5bdfec1963.htm">SpriteToBack</a></td><td><div class="summary">
Change the display order of the specified sprite so it goes behind all other sprites.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="80b0403d-da14-c176-9d01-080fc170a67d.htm">SpriteToFront</a></td><td><div class="summary">
Change the display order of the specified sprite so it goes in front of all other sprites.
</div></td></tr><tr data="public;inherited;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="http://msdn2.microsoft.com/en-us/library/7bxwbwt2" target="_blank">ToString</a></td><td><div class="summary">Returns a string that represents the current object.</div> (Inherited from <a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">Object</a>.)</td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubmethod.gif" alt="Public method" title="Public method" /></td><td><a href="675951bb-e09a-e9ec-95d2-c0efaf187d6d.htm">UnPause</a></td><td><div class="summary">
un-Pause everything. This will send the specified SpritePauseType unpause command
to all sprites.
</div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID7RB')" onkeypress="SectionExpandCollapse_CheckKey('ID7RB', event)" tabindex="0"><img id="ID7RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Events</span></div><div id="ID7RBSection" class="collapsibleSection"><table class="members" id="eventList"><tr><th class="iconColumn">
 
</th><th>Name</th><th>Description</th></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubevent.gif" alt="Public event" title="Public event" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="ba843001-e657-41e8-7c66-c2473781ed40.htm">DoTick</a></td><td><div class="summary">
The function called by the timer every 10 millisecods This is usually where you will do the majority of the work.
You can define this manually, or when you <a href="d20e5816-faf3-723d-5f2d-ebff462012f1.htm">instantiate the SpriteController</a></div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID8RB')" onkeypress="SectionExpandCollapse_CheckKey('ID8RB', event)" tabindex="0"><img id="ID8RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Fields</span></div><div id="ID8RBSection" class="collapsibleSection"><table class="members" id="fieldList"><tr><th class="iconColumn">
 
</th><th>Name</th><th>Description</th></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubfield.gif" alt="Public field" title="Public field" /></td><td><a href="34a7b0e2-8fce-a07e-fff0-5460ba02a4cf.htm">OptimizeForLargeSpriteImages</a></td><td><div class="summary">
If your sprite images need substantial growing or shrinking when displayed, you can try setting this to "true"
to see if it makes it run any faster. What it does is to resize the image once, and keep a cached copy of that
image at that size. If you use the same sprite, but with different sizes, setting this to "True" may actually slow
down the game instead of speeding it up.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubfield.gif" alt="Public field" title="Public field" /></td><td><a href="b9f05ef6-f80c-5676-1eca-d73833dca177.htm">RandomNumberGenerator</a></td><td><div class="summary">
Since everything needs a random number generator, we make one that should be accessible throughout your program.
</div></td></tr><tr data="public;declared;notNetfw;"><td><img src="../icons/pubfield.gif" alt="Public field" title="Public field" /><img src="../icons/CodeExample.png" alt="Code example" title="Code example" /></td><td><a href="f640b978-f990-84a2-015a-40bf256fc37d.htm">SpriteComparisonDelegate</a></td><td><div class="summary">
Allow the sprite sort-method to be overridden.
</div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID9RB')" onkeypress="SectionExpandCollapse_CheckKey('ID9RB', event)" tabindex="0"><img id="ID9RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Examples</span></div><div id="ID9RBSection" class="collapsibleSection">
A sprite controller controls animations and
can help you check for <a href="7fc92c27-7895-2b2c-d4f1-ac682eec7af5.htm">key-presses.</a> To make a sprite controller,
you need to have one defined for your main form:
<div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID1EADABA_tab1" class="codeSnippetContainerTabSingle">C#</div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID1EADABA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID1EADABA');return false;" title="Copy">Copy</a></div></div><div id="ID1EADABA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve">SpriteController MySpriteController;</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID1EADABA");</script>
And then, when the form is created, after the InitializeComponents() function, you
need to configure the drawing area and create the sprite controller:
<div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID1EABABA_tab1" class="codeSnippetContainerTabSingle">C#</div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID1EABABA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID1EABABA');return false;" title="Copy">Copy</a></div></div><div id="ID1EABABA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve">MainDrawingArea.BackgroundImage = Properties.Resources.Background;
MainDrawingArea.BackgroundImageLayout = ImageLayout.Stretch;
MySpriteController = <span class="highlight-keyword">new</span> SpriteController(MainDrawingArea);</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID1EABABA");</script>
In this case, MainDrawingArea is the picturebox where all the sprites will be displayed.
</div><div class="collapsibleAreaRegion" id="seeAlsoSection"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID10RB')" onkeypress="SectionExpandCollapse_CheckKey('ID10RB', event)" tabindex="0"><img id="ID10RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />See Also</span></div><div id="ID10RBSection" class="collapsibleSection"><h4 class="subHeading">Reference</h4><div class="seeAlsoStyle"><a href="6b7227c0-7a6a-6342-3b08-917c7de429cc.htm">SpriteLibrary Namespace</a></div></div></div></div><div id="pageFooter" class="pageFooter"> </div></body></html>