หลายคนที่โหลดชุดพัฒนา XNA Game Studio 3.1 มาจะเห็นมามันแถม Platform Stater Kit Source Code ของเกมแนว Platform Side Scrolling (ตลุยด่านแบบด้านข้าง) และลอง Compile ดูจะเห็นว่ามันใช้งานได้ 100% แต่ติดตรงทำไมเรา Edit Level แล้วทำมัย ตัวเกมมันถึง Fixed หน้าจอเดินไปขวาหรือซ้านยสุดก็ชนขอบ ทำไงจะให้ ไปทางซ้ายหรือฉากก็เลื่อนซ้ายขวาต่อ หากมีอาการคันไม้คันมือไม่รู้จะเริ่มยังไง ผมไป ศึกษามาให้แล้วครับ
ก่อนอื่นเลย หากเครื่องของคุณยังไม่ลง XNA Studio 3.0 หรือ 3.1 ให้ไปดาวน์โหลดมาติดตั้ง ก่อนนะครับ
ที่เวป www.xna.com เลยครับ หาไม่เข้าใจก็ไปอ่านบทความย้อนหลังได้ที่นี่ครับ XNA Studio 3.1 คลอดแล้ว!
และ ถ้าอยากรู้ว่า Platform Starter Kit เกมที่แถมมากับชุดพัฒนาเป็นยังไงก็ไปอ่านบทความที่นี่ก่อนครับ
XNA Starter Kit: Platformer แล้วจะรู้ครับ และเป็นประโยชน์ที่จะเริ่ม
ผมได้ไปอ่าน บทความการใช้งาน Library ของ XNA จากที่นี่ครับ http://msdn.microsoft.com
เค้าได้อธิบายอย่างชัดเจนเลยว่าการจะให้มัน Scrolling ฉากหลังแบบ Layer นั้นทำได้ และต้อง Debug
ชุด code เล็กน้อยเท่านั้นเองครับ
เริ่มเลยครับ ให้เราไปเปิดไฟล์โปรเจ็ค ชื่อ PlatformerGame.cs
แล้วทำการแก้ไข code เล็กน้อยครับ โดยไปที่ ฟังก์ชั่น ชื่อว่า Draw แล้วทำการ remove หรือ ลบ code สอง บรรทัดนี้
บรรทัดแรกเลยคือ
1 |
spriteBatch.Begin(); |
และบรรทัดที่สองคือ
1 |
spriteBatch.End(); |
ตามตัวอย่างครับ
1 |
<span style="font-size: x-small;"><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;"><span style="color: #0000ff;">override</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span> Draw(<span style="color: #2b91af;"><span style="color: #2b91af;">GameTime</span></span> gameTime) </span><p><span style="font-size: x-small;">{</span></p><p><span style="font-size: x-small;">graphics.GraphicsDevice.Clear(<span style="color: #2b91af;"><span style="color: #2b91af;">Color</span></span>.CornflowerBlue);</span></p><p><span style="color: #008000;"><span style="color: #008000; font-size: x-small;">//spriteBatch.Begin(); --->ลบอกไป</span></span></p><p><span style="font-size: x-small;">level.Draw(gameTime, spriteBatch);</span></p><p><span style="font-size: x-small;">DrawHud();</span></p><p><span style="color: #008000;"><span style="color: #008000; font-size: x-small;">//spriteBatch.End(); ---> ลบออกไป</span></span></p><span style="font-size: x-small;"><span style="color: #0000ff;"><span style="color: #0000ff;">base</span></span>.Draw(gameTime); </span><p><span style="font-size: x-small;">}</span></p> |
โอเคครับหลังจากนั้น เราก็ไป ที่ ฟังก์ชั่นที่ชื่อว่า DrawHud ครับแล้วไปเพิ่ม Code ที่หน้าตาคล้าย
สองรรทัดที่แล้ว ที่ตรง บรรทัดแรกใรฟังก์ชั่นและ บรรทัดสุดท้ายตอนปิด ฟังก์ชั่น ครับ
ตามตัวอย่าง บรรทัดนี้ ใครที่หา ฟังก์ชั้นไม่เจอก็ทำตามภาพครับ
1 |
<span style="font-size: x-small;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span> DrawHud() </span><p><span style="font-size: x-small;">{</span></p><p><span style="color: #008000;"><span style="color: #008000; font-size: x-small;">//Nuy Debug ส่วนที่เพิ่มมา</span></span></p><p><span style="font-size: x-small;">spriteBatch.Begin();</span></p><p><span style="color: #008000; font-size: x-small;">//Nuy Debug ส่วนที่เพิ่มมา</span></p><span style="font-size: x-small;"><span style="color: #2b91af;"><span style="color: #2b91af;">Rectangle</span></span> titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea; </span><p><span style="font-size: x-small;"><span style="color: #2b91af;"><span style="color: #2b91af;">Vector2</span></span> hudLocation = <span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Vector2</span></span>(titleSafeArea.X, titleSafeArea.Y);</span></p><span style="font-size: x-small;"><span style="color: #2b91af;"><span style="color: #2b91af;">Vector2</span></span> center = <span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Vector2</span></span>(titleSafeArea.X + titleSafeArea.Width / 2.0f, </span><p><span style="font-size: x-small;">titleSafeArea.Y + titleSafeArea.Height / 2.0f);</span></p><p><span style="font-size: x-small;">.....</span></p><span style="color: #008000;"><span style="color: #008000; font-size: x-small;"><p>//Nuy Debug ส่วนที่เพิ่มมา</p></span></span><p><span style="font-size: x-small;">spriteBatch.End();</span></p><p><span style="color: #008000; font-size: x-small;">//Nuy Debug ส่วนที่เพิ่มมา</span></p><p><span style="font-size: x-small;">}</span></p> |
เมื่อเสร็จขั้นตอนนี้แล้วครับ ก็ไปเปิด ไฟล์ที่ชื่อว่า Level.cs ที่โปรเจ็คครับ
ให้ไปแก้ไข Code ที่บรรทัดนี้
1 |
<span style="color: blue"><p><span style="color: blue">private</span> Layer[] layers;</p><p>ให้แก้ไขเป็น</p><p><span style="color: blue">private</span> <span style="color: blue">float</span> cameraPosition;</p><p>เมื่อจัดการเสร้จแล้วไปที่ ฟังก์ชั่นที่ชื่อว่า Layer ครับ ทำการ Comment code ชุดเก่า แล้ว replace ชุดใหม่เข้าไปดัง ตัวอย่างครับ</p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">public</span></span><span style="font-size: x-small;"> Level(</span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">IServiceProvider</span></span><span style="font-size: x-small;"> serviceProvider, </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">string</span></span><span style="font-size: x-small;"> path)</span><span style="font-size: x-small;"> <p>{</p><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Create a new content manager to load content used just by this level.</span></span></p></span><span style="font-size: x-small;">content = </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">ContentManager</span></span><span style="font-size: x-small;">(serviceProvider, </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Content"</span></span><span style="font-size: x-small;">);</span><span style="font-size: x-small;">timeRemaining = </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">TimeSpan</span></span><span style="font-size: x-small;">.FromMinutes(2.0);</span><span style="font-size: x-small;"> <p>LoadTiles(path);</p><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Load background layer textures. For now, all levels must</span></span></p></span><span style="font-size: x-small;"><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// use the same backgrounds and only use the left-most part of them.</span></span></p></span><span style="font-size: x-small;"><p> </p><p> </p></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*เริ่มต้นทำการคอมเม็น code ชุดนี้</span></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;"> <p>layers = new Texture2D[3];</p><p>for (int i = 0; i < layers.Length; ++i)</p><p>{</p><p>// Choose a random segment if each background layer for level variety.</p><p>int segmentIndex = random.Next(3);</p><p>layers[i] = Content.Load<Texture2D>("Backgrounds/Layer" + i + "_" + segmentIndex);</p><p>}</p><p>/*สิ้นสุดทำการคอมเม็น code ชุด</p><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Load sounds.</span></span></p><span style="font-size: x-small;">exitReachedSound = Content.Load<</span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">SoundEffect</span></span><span style="font-size: x-small;">>(</span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Sounds/ExitReached"</span></span><span style="font-size: x-small;">);</span></span><span style="font-size: x-small;"> <p>}</p><p> </p></span></span></span><span style="font-size: x-small;">แล้วทำการ เพิ่ม Code ชุดข้างล่างนี้ลงไปครับ </span> |
1 |
<span style="font-size: x-small;">layers = <span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Layer</span></span>[3]; </span><p><span style="font-size: x-small;">layers[0] = <span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Layer</span></span>(Content, <span style="color: #a31515;"><span style="color: #a31515;">"Backgrounds/Layer0"</span></span>, 0.2f);layers[1] = </span></p><span style="font-size: x-small;"><span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Layer</span></span>(Content, <span style="color: #a31515;"><span style="color: #a31515;">"Backgrounds/Layer1"</span></span>, 0.5f);layers[2] = <span style="color: #0000ff;"><span style="color: #0000ff;">new</span></span> <span style="color: #2b91af;"><span style="color: #2b91af;">Layer</span></span>(Content, <span style="color: #a31515;"><span style="color: #a31515;">"Backgrounds/Layer2"</span></span>, 0.8f); </span> |
จะได้ ดังตัวอย่าง ทั้งฟังก์ชั่นดัง รูปแบบด้านล่างครับ
1 |
<span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">public</span></span><span style="font-size: x-small;"> Level(</span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">IServiceProvider</span></span><span style="font-size: x-small;"> serviceProvider, </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">string</span></span><span style="font-size: x-small;"> path)</span></span><span style="font-size: x-small;"> </span><span style="font-size: x-small;"><p>{</p><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Create a new content manager to load content used just by this level.</span></span></p></span><span style="font-size: x-small;">content = </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">ContentManager</span></span><span style="font-size: x-small;">(serviceProvider, </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Content"</span></span><span style="font-size: x-small;">);</span><span style="font-size: x-small;">timeRemaining = </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">TimeSpan</span></span><span style="font-size: x-small;">.FromMinutes(2.0);</span><span style="font-size: x-small;"> <p>LoadTiles(path);</p><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Load background layer textures. For now, all levels must</span></span></p></span><span style="font-size: x-small;"><p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// use the same backgrounds and only use the left-most part of them.</span></span></p></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*Nuy Debug</span></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;"> </span></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;"><p>layers = new Texture2D[3];</p><p>for (int i = 0; i < layers.Length; ++i)</p><p>{</p><p>// Choose a random segment if each background layer for level variety.</p><p>int segmentIndex = random.Next(3);</p><p>layers[i] = Content.Load<Texture2D>("Backgrounds/Layer" + i + "_" + segmentIndex);</p><p>}*/</p></span></span><span style="font-size: x-small;">layers = </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">Layer</span></span><span style="font-size: x-small;">[3];</span><span style="font-size: x-small;"> <p>layers[0] = <span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">Layer</span></span><span style="font-size: x-small;">(Content, </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Backgrounds/Layer0"</span></span><span style="font-size: x-small;">, 0.2f);layers[1] = </span></p></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">Layer</span></span><span style="font-size: x-small;">(Content, </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Backgrounds/Layer1"</span></span><span style="font-size: x-small;">, 0.5f);</span><span style="font-size: x-small;">layers[2] = </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span><span style="font-size: x-small;"> </span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">Layer</span></span><span style="font-size: x-small;">(Content, </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Backgrounds/Layer2"</span></span><span style="font-size: x-small;">, 0.8f);</span><span style="font-size: x-small;"> <p><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">// Load sounds.</span></span></p></span><span style="font-size: x-small;">exitReachedSound = Content.Load<</span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">SoundEffect</span></span><span style="font-size: x-small;">>(</span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">"Sounds/ExitReached"</span></span><span style="font-size: x-small;">);</span><span style="font-size: x-small;"> <p>}</p></span> |
อ่ะใจเย็นอย่าเพิ่ง งง กันนะครับ ยังไปได้อีก
ในไฟล์ Level.cs นี่แหละครับให้ นำ Code ชุดข้างล่างนี้ไปวางแทนที่ ฟังก์ชั่น Draw ชุดเก่าเลยครับ
1 |
<span style="color: blue">public</span> <span style="color: blue">void</span> Draw(GameTime gameTime, SpriteBatch spriteBatch) |
1 |
{ |
1 |
spriteBatch.Begin(); |
1 |
<span style="color: blue">for</span> (<span style="color: blue">int</span> i = 0; i <= EntityLayer; ++i) |
1 |
layers[i].Draw(spriteBatch, cameraPosition); |
1 |
spriteBatch.End(); |
1 |
<br /> ScrollCamera(spriteBatch.GraphicsDevice.Viewport); |
1 |
Matrix cameraTransform = Matrix.CreateTranslation(-cameraPosition, 0.0f, 0.0f); |
1 |
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, cameraTransform); |
1 |
<br /> DrawTiles(spriteBatch); |
1 |
<br /> <span style="color: blue">foreach</span> (Gem gem <span style="color: blue">in</span> gems) |
1 |
gem.Draw(gameTime, spriteBatch); |
1 |
<br /> Player.Draw(gameTime, spriteBatch); |
1 |
<br /> <span style="color: blue">foreach</span> (Enemy enemy <span style="color: blue">in</span> enemies) |
1 |
enemy.Draw(gameTime, spriteBatch); |
1 |
<br /> spriteBatch.End(); |
1 |
<br /> spriteBatch.Begin(); |
1 |
<span style="color: blue">for</span> (<span style="color: blue">int</span> i = EntityLayer + 1; i < layers.Length; ++i) |
1 |
layers[i].Draw(spriteBatch, cameraPosition); |
1 |
spriteBatch.End(); |
1 |
} |
แล้วไปจัดการที่ ฟังก์ชั่น DrawTiles ครับ บรรทัดแรกของฟังก์ชั่นให้แทรก Code ด้านล่าง
1 |
<span style="color: #008000;">// Calculate the visible range of tiles.</span> |
1 |
<span style="color: blue">int</span> left = (<span style="color: blue">int</span>)Math.Floor(cameraPosition / Tile.Width); |
1 |
<span style="color: blue">int</span> right = left + spriteBatch.GraphicsDevice.Viewport.Width / Tile.Width; |
1 |
right = Math.Min(right, Width - 1); |
แล้วไปที่ loop ครับ จะเห็น loop ที่มี loop ซ้อนให้นำ code ด้านล่างนี้ไปวางที inner Loop หรือ Loop X ภายในครับ
1 |
<span style="color: blue">for</span> (<span style="color: blue">int</span> x = left; x <= right; ++x) |
เสร็จแล้วให้คุณ เขียนฟังก์ชั่นขึ้นมาใหม่ครับ ตาม code fuction ชุดนี้เลย
1 |
<span style="color: blue">private</span> <span style="color: blue">void</span> ScrollCamera(Viewport viewport) |
1 |
{ |
1 |
#<span style="color: blue">if</span> ZUNE |
1 |
<span style="color: blue">const</span> <span style="color: blue">float</span> ViewMargin = 0.45f; |
1 |
#<span style="color: blue">else</span> |
1 |
<span style="color: blue">const</span> <span style="color: blue">float</span> ViewMargin = 0.35f; |
1 |
#endif |
1 |
<br /> <span style="color: green">// Calculate the edges of the screen.</span> |
1 |
<span style="color: blue">float</span> marginWidth = viewport.Width * ViewMargin; |
1 |
<span style="color: blue">float</span> marginLeft = cameraPosition + marginWidth; |
1 |
<span style="color: blue">float</span> marginRight = cameraPosition + viewport.Width - marginWidth; |
1 |
<br /> <span style="color: green">// Calculate how far to scroll when the player is near the edges of the screen.</span> |
1 |
<span style="color: blue">float</span> cameraMovement = 0.0f; |
1 |
<span style="color: blue">if</span> (Player.Position.X < marginLeft) |
1 |
cameraMovement = Player.Position.X - marginLeft; |
1 |
<span style="color: blue">else</span> <span style="color: blue">if</span> (Player.Position.X > marginRight) |
1 |
cameraMovement = Player.Position.X - marginRight; |
1 |
<br /> <span style="color: green">// Update the camera position, but prevent scrolling off the ends of the level.</span> |
1 |
<span style="color: blue">float</span> maxCameraPosition = Tile.Width * Width - viewport.Width; |
1 |
cameraPosition = MathHelper.Clamp(cameraPosition + cameraMovement, 0.0f, maxCameraPosition); |
1 |
} |
หนุกหนานพอยังครับมันยังไม่จบ Hilight ของ งานนี้โปล่มาแล้ว เราต้องทำการ Add Class
ใน Project ของเราครับ ตามรูปเลยให้ Add Class ใหม่ขึ้นมาครับ
แล้วให้ตั้งชื่อว่า Layer.cs ครับ
ซึ่งในไฟล์นี้ บน Header ให้คุณใส่ Code ด้านล่าง
1 |
<span style="color: blue">using</span> Microsoft.Xna.Framework; <br /><span style="color: blue">using</span> Microsoft.Xna.Framework.Graphics; <br /><span style="color: blue">using</span> Microsoft.Xna.Framework.Content; |
1 |
และประกาศ properties ให้กับ Class นี้ครับ ดังตัวอย่งด้านล่าง |
1 |
<span style="color: blue">public</span> Texture2D[] Textures { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; } <br /><span style="color: blue">public</span> <span style="color: blue">float</span> ScrollRate { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; } |
1 |
แล้วตามด้วย Source code function 2 อันนี้ก็เป็นอันเสร็จประการครับ |
1 |
<span style="color: blue">public</span> Layer(ContentManager content, <span style="color: blue">string</span> basePath, <span style="color: blue">float</span> scrollRate)<br /> {<br /> <span style="color: green">// Assumes each layer only has 3 segments.</span><br /> Textures = <span style="color: blue">new</span> Texture2D[3];<br /> <span style="color: blue">for</span> (<span style="color: blue">int</span> i = 0; i < 3; ++i)<br /> Textures[i] = content.Load<Texture2D>(basePath + <span style="color: maroon"><span style="color: maroon">"_"</span></span> + i);<br /><br /> ScrollRate = scrollRate;<br /> }<br /> |
1 |
<span style="color: blue">public</span> <span style="color: blue">void</span> Draw(SpriteBatch spriteBatch, <span style="color: blue">float</span> cameraPosition) |
1 |
{ |
1 |
<span style="color: green">// Assume each segment is the same width.</span> |
1 |
<span style="color: blue">int</span> segmentWidth = Textures[0].Width; <span style="color: green">// Calculate which segments to draw and how much to offset them.</span> |
1 |
<span style="color: blue">float</span> x = cameraPosition * ScrollRate; |
1 |
<span style="color: blue">int</span> leftSegment = (<span style="color: blue">int</span>)Math.Floor(x / segmentWidth); |
1 |
<span style="color: blue">int</span> rightSegment = leftSegment + 1; |
1 |
x = (x / segmentWidth - leftSegment) * -segmentWidth; |
1 |
<br /> spriteBatch.Draw(Textures[leftSegment % Textures.Length], <span style="color: blue">new</span> Vector2(x, 0.0f), Color.White); |
1 |
spriteBatch.Draw(Textures[rightSegment % Textures.Length], <span style="color: blue">new</span> Vector2(x + segmentWidth, 0.0f), Color.White); |
1 |
} |
วิธีทดลองอยากรู้ว่าเกมเราจะ เดินไปสุดจอด้านขวาแล้วฉากจะเลื่อนให้มั้ยก็ไปเปิดไฟล์ Level0.txt ที่
Folder \HighResolutionContent\Levels\0.txt ครับแล้วลองใส่ Sample data ตามข้างล่างนี้ ระวัง! ตรวจสอบดีๆนะครับ
ห้ามมีการเคาะบรรทัดจนเกิด 16 บรรทัดหล่ะ Compile ไม่ผ่านอย่ามาโวยวายนะจ๊ะ
……………………………………………………………………
……………………………………………………………………
………………………G……………………………………….X…
……………………..###……………………………….############
………………….G……………………………………………….
…………………###…………….G.GDG………….G.G.G……………
……………..G………………..#########……….#######…………..
…………….###…………………………………………………..
…………G……………….G.G……………G.G…………………….
………..###……………..#####………….#####……………………
…….G…………………………………………………………….
……###………………………….GDG.G………….G.G.G.G.G.G.G.G.G.G.
………………………………..#########………##.G.G.G.G.G.G.G.G.G..
.1………………………………………………..GCG.G.G.GCG.G.G.GCG.
####################………………………………..####################
เห็นมั้ย สนุกไม่ยากหากใฝ่รู้ ส่วนใครที่ทำยังไง๊ยังไง ก็ไม่ผ่านอาจจะขาดทักษะ ก็ดาวน์โหลด Project
ที่ผมทำไว้แล้ว run ได้ 100%
ไป Rebuild และ Compile ใหม่ดีกว่าเลย
ดาวน์โหลดที่นี่ครับ http://www.daydev.com/project/xna/lession1.zip