SpriteLibrary/SpriteLibrary/Doc/Help/html/2c9b874d-5097-98bf-908c-f6b...

30 lines
9.5 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.ReplaceOriginalImage Method </title><meta name="Language" content="en-us" /><meta name="System.Keywords" content="ReplaceOriginalImage method" /><meta name="System.Keywords" content="SpriteController.ReplaceOriginalImage method" /><meta name="Microsoft.Help.F1" content="SpriteLibrary.SpriteController.ReplaceOriginalImage" /><meta name="Microsoft.Help.Id" content="Overload:SpriteLibrary.SpriteController.ReplaceOriginalImage" /><meta name="Microsoft.Help.ContentType" content="Reference" /><meta name="BrandingAware" content="true" /><meta name="container" content="SpriteLibrary" /><meta name="file" content="2c9b874d-5097-98bf-908c-f6bac5d647d3" /><meta name="guid" content="2c9b874d-5097-98bf-908c-f6bac5d647d3" /><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="toclevel0" data-toclevel="0"><a class="tocCollapsed" 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="toclevel0" data-toclevel="0"><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="toclevel1 current" data-toclevel="1" data-childrenloaded="true"><a class="tocExpanded" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="2c9b874d-5097-98bf-908c-f6bac5d647d3.htm" title="ReplaceOriginalImage Method " tocid="2c9b874d-5097-98bf-908c-f6bac5d647d3">ReplaceOriginalImage Method </a></div><div class="toclevel2" data-toclevel="2"><a data-tochassubtree="false" href="49befa66-d9d0-400c-1fc2-ac57f17433f1.htm" title="ReplaceOriginalImage Method " tocid="49befa66-d9d0-400c-1fc2-ac57f17433f1">ReplaceOriginalImage Method </a></div><div class="toclevel2" data-toclevel="2"><a data-tochassubtree="false" href="eac30137-8237-e01a-ee3d-e599d117c03e.htm" title="ReplaceOriginalImage Method (Image)" tocid="eac30137-8237-e01a-ee3d-e599d117c03e">ReplaceOriginalImage Method (Image)</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<span id="LST5A2754AF_0"></span><script type="text/javascript">AddLanguageSpecificTextSet("LST5A2754AF_0?cpp=::|nu=.");</script>ReplaceOriginalImage Method </td></tr></table><span class="introStyle"></span> <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" />Overload List</span></div><div id="ID2RBSection" class="collapsibleSection"><table class="members" id="overloadMembersList"><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="49befa66-d9d0-400c-1fc2-ac57f17433f1.htm">ReplaceOriginalImage<span id="LST5A2754AF_1"></span><script type="text/javascript">AddLanguageSpecificTextSet("LST5A2754AF_1?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('ID1RB')" onkeypress="SectionExpandCollapse_CheckKey('ID1RB', event)" tabindex="0"><img id="ID1RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Examples</span></div><div id="ID1RBSection" 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="ID0EAAAAACDA_tab1" class="codeSnippetContainerTabSingle">C#</div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID0EAAAAACDA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID0EAAAAACDA');return false;" title="Copy">Copy</a></div></div><div id="ID0EAAAAACDA_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("ID0EAAAAACDA");</script></div></div></td></tr></table><a href="#PageHeader">Top</a></div><div class="collapsibleAreaRegion" id="seeAlsoSection"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID3RB')" onkeypress="SectionExpandCollapse_CheckKey('ID3RB', event)" tabindex="0"><img id="ID3RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />See Also</span></div><div id="ID3RBSection" class="collapsibleSection"><h4 class="subHeading">Reference</h4><div class="seeAlsoStyle"><a href="07a473e4-4716-e5b9-c7d2-c4748265fc58.htm">SpriteController Class</a></div><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>