<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>I can&#39;t assign a returned bitmap pointer</title>
		<link>http://www.allegro.cc/forums/view/591591</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 28 May 2007 13:59:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am making a prototype for a 2D fighting game in C++ using allegro, but I am having trouble incorporating classes into it. I have narrowed the one function in my kCharacter class to</p><p>BITMAP *kCharacter::Walk ()<br />{<br /> return CharacterImage;<br />}</p><p>In int main (), the code I have for assigning this bitmap is</p><p>kCharacter * Player1; //Player1 class<br />BITMAP * Player1Image //Player1&#39;s current Image</p><p>if (key[KEY_LEFT])<br />{<br /> Player1Image = Player1-&gt;Walk ();<br />}</p><p>I&#39;m not really sure what is going on. I have CharacterImage declared in kCharacter and I have it initialised in the constructor. What happens is, the text I have in the code before the if statement works grand, but then when it gets to the if statement windows experiences a problem with the applicatino a closes it down. Any help would be appreciated, thanks.</p><p>P.S. Please don&#39;t flame me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zanmoto)</author>
		<pubDate>Sat, 26 May 2007 18:06:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>More code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 26 May 2007 18:13:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Steve.h</p><p>#include &lt;allegro.h&gt;</p><p>class CCharacter<br />{<br /> public:<br />  CCharacter ();<br />  ~CCharacter ();<br />  <br />  <br />  int x;<br />  int y;<br />  <br />  BITMAP * CharacterWait;<br />  <br />  BITMAP * Wait ();<br />};</p><p>CCharacter::CCharacter ()<br />{<br /> x = 20;<br /> y = 50;<br /> <br /> CharacterWait = create_bitmap (32, 32);<br /> clear_bitmap (CharacterWait);<br /> CharacterWait = load_bitmap (&quot;Character_Wait.bmp&quot;, NULL);<br />}</p><p>CCharacter::~CCharacter ()<br />{<br /> x = 0;<br /> y = 0;<br /> destroy_bitmap (CharacterWait);<br />}</p><p>BITMAP * CCharacter::Wait ()<br />{<br /> return CharacterWait;<br />}</p><p>Main.cpp</p><p>#include &quot;Steve.h&quot;</p><p>#define MODE GFX_AUTODETECT_WINDOWED<br />#define WIDTH 500<br />#define HEIGHT 100</p><p>#define WHITE makecol (255, 255, 255)</p><p>int main ()<br />{<br /> allegro_init();<br /> install_timer();<br /> install_keyboard();<br /> set_color_depth(32);<br /> set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);<br /> <br /> CCharacter * Player1;<br /> BITMAP * Player1_Image;<br /> <br /> textprintf_ex (screen, font, 0, 0, WHITE, 0, &quot;Text Sample Number 1&quot;);<br /> <br /> while (!key[KEY_ESC])<br /> {<br />  textprintf_ex (screen, font, 0, 10, WHITE, 0, &quot;Text Sample Number 2&quot;);<br />  <br />  {<br />   Player1_Image = Player1-&gt;Wait ();<br />  }<br />  <br />  textprintf_ex (screen, font, 0, 90, WHITE, 0, &quot;Text Sample Number 3&quot;);<br />  <br />  draw_sprite (screen, Player1_Image, Player1-&gt;x, Player1-&gt;y);<br />  rest (100);<br /> }<br /> <br /> Player1-&gt;~CCharacter ();<br /> allegro_exit ();<br /> return 0;<br />}END_OF_MAIN();
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zanmoto)</author>
		<pubDate>Sat, 26 May 2007 18:18:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are many things wrong here.</p><p>1) You never create a CCharacter object, just declare a pointer to one.<br />2) You create a bitmap and then just throw it away in the constructor.<br />3) You manually call the destructor, which you shouldn&#39;t do (unless you really, really know what you&#39;re doing, and those cases are rare).<br />4) You didn&#39;t use the code tags when making this post.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 26 May 2007 18:29:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1) You never create a CCharacter object, just declare a pointer to one.<br /> RE: How do I do that?<br />2) You create a bitmap and then just throw it away in the constructor.<br /> RE: How did I do that?<br />3) You manually call the destructor, which you shouldn&#39;t do (unless you really, really know what you&#39;re doing, and those cases are rare).<br /> RE: I&#39;m going fixing this now.<br />4) You didn&#39;t use the code tags when making this post.<br /> RE: Sorry about that. Do you use BBcode or HTML on this site?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zanmoto)</author>
		<pubDate>Sat, 26 May 2007 18:35:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1)
</p><div class="source-code snippet"><div class="inner"><pre>CCharacter <span class="k3">*</span> Player1 <span class="k3">=</span> <span class="k1">new</span> CCharacter<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

2)
</p><div class="source-code snippet"><div class="inner"><pre>CharacterWait <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a> <span class="k2">(</span><span class="n">32</span>, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/clear_bitmap" target="_blank"><span class="a">clear_bitmap</span></a> <span class="k2">(</span>CharacterWait<span class="k2">)</span><span class="k2">;</span>
CharacterWait <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a> <span class="k2">(</span><span class="s">"Character_Wait.bmp"</span>, NULL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
The first two lines are superflous. load_bitmap will create a bitmap for you. All you need is
</p><div class="source-code snippet"><div class="inner"><pre>CharacterWait <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a> <span class="k2">(</span><span class="s">"Character_Wait.bmp"</span>, NULL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

4) [.code] ... [./code] without the .&#39;s after the [
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Sat, 26 May 2007 18:37:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you <u><i>soo</i></u> much everyone! This is all valuable programming experience!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zanmoto)</author>
		<pubDate>Sat, 26 May 2007 18:45:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>May I kindly suggest that you consider reading a C++ introduction? It seems like you might have a lot of potential to improve your knowledge of the basics of this language.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 26 May 2007 22:35:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t worry, I have read enough C++ stuff (I know that isn&#39;t possible), i.e. &quot;Game Programming all in One 1st and 3rd ed.&quot;, and a number of online tutorials. It&#39;s just practical experience I lack, especially with classes as there aren&#39;t many tutorials on game programming with them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zanmoto)</author>
		<pubDate>Mon, 28 May 2007 02:43:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In that case I&#39;d suggest that you consider reading the books and playing around with the examples presented there. I am aware that the examples in these books won&#39;t be as exciting as writing a game. But please consider that learning the language and then using that knowledge to create a game will be more fun that starting with the game, getting frustrated and knowing neither the language or how to program games at the end.</p><p>Another option would be to <i>read</i> the books. Where reading means &quot;reading the book in a way, that you actually remember what was written in it.&quot;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Mon, 28 May 2007 13:59:06 +0000</pubDate>
	</item>
</rss>
