크로스 플랫폼 게임 프레임워크




                                        새롭게        VS 2010     강력해짂
                    Windows   게임개발에                             사운드
                    Phone 7             추가된      Integration
                              특화된 API   Effect                 Support
                      지원



커뮤니티 => 인디게임으로 변화
처음부터 크로스 플랫폼을 지원하기 위한
프레임워크로 개발됨



다른 기기 별 포팅 비용의 최소화



Visual Studio에서 디바이스 별 프로젝트
관련 작업 모두 수행가능
디바이스 호홖성을 위한 개발일 경우
Reach   Windows Phone 7, Windows, XBOX360에서 모두 동작


        특정 디바이스와 특정 홖경에 맞춘 게임 개발일 경우
HiDef   Xbox 360/Windows Only
어떻게 하면 게임 개발을 쉽게 할 수 있을까?

C/C++은 어렵고, Direct API도 어렵다.
Sound와 Input 처리는 또 뭔가를 배워야 하고
Network를 위해 Socket도 배워야한다.. 정말 많다.
                                                         Creating
                                                          Games
XNA는 게임 개발에 특화된 C# 기반의 Framework
 - XNA 하나로 Graphic, Input, Network, Sound, Resource 해결

초보자를 위한 많은 튜토리얼과 예제

Visual Studio 2010 완벽 지원

크로스 플랫폼 지원 - XBOX360, Windows PC, WP7을 최소한의
            코드 수정으로 동시 개발 가능
Developer Tools                               Platform Technology




                                          Cloud Services

Location Service




                   Notification Service
Objective-C
                                          배우기
                                        어렵다. T.T
                                                       한번 만들어
                                                      여러 디바이스에
                                                      홗용하고 싶다.



인기 순위에서는 충분히 개발할만한 단계에 와 있는 것 같음 ^^;
게임 제작에 적합한 언어의 특징 - 속도? 확장성? 기본 제공 라이브러리?
핵심적인 부분의 최적화, 확장성 그리고 게임제작의 용이성이 중요!

Mono Framework의 움직임에 관심을 가져야 함
- XNA로 개발한 게임을 아이폰, 안드로이드에 포팅할 수 있게 됨
- Mono(iOS, Android) + XNA Touch 조합
XNA를 이용한 게임 개발
Load
Initialize
             Content


                       XNA Framework = API + Application Model

             Update


              Draw




             Unload
                                End
             Content
XNA Framework Game Loop Example
                                            public class Game1 : Microsoft.Xna.Framework.Game
                                            {
Initialize, LoadContent는 최초 1번만 호출              SpriteBatch spriteBatch;


Update/Draw 는 매 frame 당 호출                      public Game1()
                                                {
                                                    graphics = new GraphicsDeviceManager(this);
                                                    Content.RootDirectory = "Content";
                                                }

                                                protected override void Initialize()
                                                {
                                                    base.Initialize();
                                                }

                                                protected override void LoadContent()
                                                {
                                                    spriteBatch = new SpriteBatch(GraphicsDevice);

Input / Network / Sound 처리 모듈은 Update에 위치       }

                                                Protected override void Update(GameTime gameTime)
Draw는 렌더링과 관련된 리소스만 처리되어야 함                     {
                                                    base.Update(gameTime);
                                                }

                                                protected override void Draw(GameTime gameTime)
                                                {
                                                    GraphicsDevice.Clear(Color.CornflowerBlue);

                                                    base.Draw(gameTime);
                                                }
                                            }
XNA Framework Texture Example

                                 public class Game1 : Microsoft.Xna.Framework.Game
                                 {
                                     GraphicsDeviceManager graphics;
                                     SpriteBatch spriteBatch;

                                     Texture2D m_ChickenTexture;

                                     protected override void LoadContent()
주의점 : 코드에서 Load시 파일명은 쓰지 않음          {
                                         spriteBatch = new SpriteBatch(GraphicsDevice);
                                         m_ChickenTexture = Content.Load<Model>("chicken");
                                     }

                                     protected override void Draw(GameTime gameTime)
                                     {
                                         GraphicsDevice.Clear(Color.CornflowerBlue);

                                         spriteBatch.Begin();
주의점 : 반드시 begin, end 사이에 그려야 함           spriteBatch.Draw(m_ChickenTexture, new Rectangle(0, 0, 480, 800),
                                                          Color.White);
                                         spriteBatch.End();

                                         base.Draw(gameTime);
                                     }
                                 }
XNA Framework Input Example
Xbox 360 Controllers (Xbox/Windows)
Keyboard (Xbox/Windows/Windows phone 7 Series)   GamePadState state = GamePad.GetState(PlayerIndex.One);

                                                 if (state.Buttons.A == ButtonState.Pressed)
                                                 {}

Touch API                                        if (state.ThumbSticks.Left.X > 0.0f)
                                                 {}

동시에 최대 4개의 Touch Input이 지원                       KeyboardState keyboard = Keyboard.GetState();

                                                 if (keyboard.IsKeyDown(Keys.Left) == true)
자동으로 회전 및 해상도를 인식하여 처리                           {}

개발자가 인식 모듈을 재정의할 수 있음
                                                 TouchCollection touches = TouchPanel.GetState();

                                                 if (touches.Count > 0)
                                                 {
Sensor API (짂동, 가속도 센서)                              switch (touches[0].State)
                                                     {
                                                         case TouchLocationState.Moved:
진동 강도 및 지속 시간 설정 가능                                         float touchX = touches[0].Position.X;
                                                            float touchY = touches[0].Position.Y;
                                                            break;
                                                         case TouchLocationState.Pressed:
                                                            break;
                                                       }
                                                 }
Cross Platform Input API                      Sensors
Xbox 360 Controllers
(Xbox/Windows)                               Location
Keyboard                                     Accelerometer
(Xbox/Windows/Windows phone 7 Series)
                                             Vibration

Touch API
Available across platforms for portability
(fewer #ifdefs)
Four points on Windows phone 7 Series
and Windows
Orientation and resolution aware
XNA Framework Sound Example
Content Processor을 Song에서 SoundEffect로 변경
Sound제어를 위해 반드시 Instance를 만들어야 함.
                                            public class Game1 : Microsoft.Xna.Framework.Game
                                            {
                                                SoundEffectInstance instance;
                                                SoundEffect m_BackMusic;

                                                protected override void LoadContent()
                                                {
                                                    m_BackMusic = Content.Load<SoundEffect>("Music");
                                                    instance = m_BackMusic.CreateInstance();

                                                }

                                                protected override void Update(GameTime gameTime)
                                                {
                                                    instance.Play();
                                                    instance.Pause();
                                                    instance.Stop();

                                                    base.Update(gameTime);
                                                }
                                            }
XNA Framework Collision Example
2D에서는 Rectangle을 주로 사용
                                 protected override void Update(GameTime gameTime)
3D에서는 BoundingSphere 및 Box를 사용   {
                                     Rectangle playerRect = new Rectangle(0, 0, 100, 100);
모두 일관된 인터페이스를 제공                     Rectangle enemyRect = new Rectangle(0,0,50,50);

                                     if (playerRect.Intersects(enemyRect) == true)
                                     {

                                     }


                                     BoundingBox playerBox = new BoundingBox(new Vector3(0,0,0), new Vector3(1,1,1));
                                     BoundingBox enemyBox = new BoundingBox();

                                     if (playerBox.Intersects(enemyBox) == true)
                                     {

                                     }

                                     BoundingSphere playerSphere = new BoundingSphere(new Vector3(0, 0, 0), 10.0f);
                                     BoundingSphere enemySphere = new BoundingSphere();

                                     if (playerSphere.Intersects(enemySphere) == true)
                                     {

                                     }


                                     base.Update(gameTime);
                                 }
XNA Framework 2D Animation Example
Update 문에서 선택되어야 될 frame 계산              int frameCount = 0;

SpriteBatch의 총 8개의 draw 함수 중 1장의 이미지에서   int frameTick = 0;
                                         Texture2D m_Run; // 이미 로딩되었다고 가정

sourceRect를 선택할 수 있는 함수 선택               public override void Update(GameTime gameTime)
                                         {
                                             const int maxiumAnimationTick = 100;
                                             const int maxiumFrame = 4;

                                             if (++frameTick > maxiumAnimationTick)
                                             {
                                                 frameTick = 0;
                                                 if (++frameCount >= maxiumFrame)
                                                     frameCount = 0;
                                             }

                                             base.Update(gameTime);
                                         }

                                         public override void Draw(GameTime gameTime)
                                         {
                                             spriteBatch.Begin();

                                             Rectangle playerRect = new Rectangle(0, 0, 96, 96);

                                             spriteBatch.Draw(m_Run, playerRect,
                                                              new Rectangle(96 * frameCount, 0, 96, 96),
                                                              Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);

                                             spriteBatch.End();
                                         }
3D Model draw Example
                                       Model testModel = Content.Load<Model>("Cube_A001_View_1x1x1");
X, FBX 파일이 사용됨 (텍스쳐 포함)
                                       Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, -120),
3D 이기 때문에 View, Projection 행렬 설정이 필요                                     new Vector3(0, 0, 0), Vector3.Up);


BasicEffect를 통해 draw
                                       Matrix projection = Matrix.CreatePerspectiveFieldOfView(
                                             MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 1000);

                                       // Draw the background.
                                       GraphicsDevice.Clear(Color.Black);

                                       Matrix[] boneTransforms = new Matrix[testModel.Bones.Count];

                                       // Look up combined bone matrices for the entire model.
                                       testModel.CopyAbsoluteBoneTransformsTo(boneTransforms);

                                       // Draw the model.
                                       foreach (ModelMesh mesh in testModel.Meshes)
                                       {
                                           foreach (BasicEffect effect in mesh.Effects)
                                           {
                                               // 행렬 설정
                                               effect.World = boneTransforms[mesh.ParentBone.Index];
                                               effect.View = view;
                                               effect.Projection = projection;

                                               effect.EnableDefaultLighting();
                                               effect.TextureEnabled = true;
                                           }

                                           mesh.Draw();
                                       }
3D Model Animation Example
                                                 public class Game1 : Microsoft.Xna.Framework.Game
                                                 {
                                                     Model testModel;

Content Processor를 SkinnedModelProcessor로 선택
                                                     AnimationPlayer animationPlayer;

                                                    protected override void LoadContent()
Default Effect를 SkinnedEffect로 선택                   {
                                                        testModel = Content.Load<Model>("chicken");

에니메이션 제어를 위한 AnimationPlayer Class를 사용                  SkinningData skinningData = testModel.Tag as SkinningData;
                                                        animationPlayer = new AnimationPlayer(skinningData);
Clip에 있는 Text 정보로 Animation 선택(ex. WAIT, HOLD)          AnimationClip clip = skinningData.AnimationClips["WAIT"];
                                                        animationPlayer.StartClip(clip);
Update문 에서 Animation Update 함수 호출                   }

                                                    protected override void Update(GameTime gameTime)
SkinnedEffect로 Draw                                 {
                                                        animationPlayer.Update(gameTime.ElapsedGameTime,
                                                                             true, Matrix.Identity);
                                                    }

                                                    protected override void Draw(GameTime gameTime)
                                                    {
                                                      // view와 projection 행렬은 기존 예제와 동일
                                                      Matrix[] bones = animationPlayer.GetSkinTransforms();

                                                        foreach (ModelMesh mesh in testModel.Meshes)
                                                        {
                                                            foreach (SkinnedEffect effect in mesh.Effects)
                                                            {
                                                                effect.SetBoneTransforms(bones);
                                                                effect.View = view;
                                                                effect.Projection = projection;
                                                                effect.EnableDefaultLighting();
                                                             }
                                                            mesh.Draw();
                                                          }
                                                    }
ImagineCup, DreamBuildPlay, 인디게임 공모전

App Hub Developer Site
Naver XNA Café, 제 블로그 Blog(Gomdong.pe.kr).

Download Visual Studio 2010 for Windows Phone
XNA Game Studio 4.0 for XP
XNA 개요 및 XNA를 이용한 게임 개발

XNA 개요 및 XNA를 이용한 게임 개발

  • 1.
    크로스 플랫폼 게임프레임워크 새롭게 VS 2010 강력해짂 Windows 게임개발에 사운드 Phone 7 추가된 Integration 특화된 API Effect Support 지원 커뮤니티 => 인디게임으로 변화
  • 2.
    처음부터 크로스 플랫폼을지원하기 위한 프레임워크로 개발됨 다른 기기 별 포팅 비용의 최소화 Visual Studio에서 디바이스 별 프로젝트 관련 작업 모두 수행가능
  • 3.
    디바이스 호홖성을 위한개발일 경우 Reach Windows Phone 7, Windows, XBOX360에서 모두 동작 특정 디바이스와 특정 홖경에 맞춘 게임 개발일 경우 HiDef Xbox 360/Windows Only
  • 4.
    어떻게 하면 게임개발을 쉽게 할 수 있을까? C/C++은 어렵고, Direct API도 어렵다. Sound와 Input 처리는 또 뭔가를 배워야 하고 Network를 위해 Socket도 배워야한다.. 정말 많다. Creating Games XNA는 게임 개발에 특화된 C# 기반의 Framework - XNA 하나로 Graphic, Input, Network, Sound, Resource 해결 초보자를 위한 많은 튜토리얼과 예제 Visual Studio 2010 완벽 지원 크로스 플랫폼 지원 - XBOX360, Windows PC, WP7을 최소한의 코드 수정으로 동시 개발 가능
  • 5.
    Developer Tools Platform Technology Cloud Services Location Service Notification Service
  • 7.
    Objective-C 배우기 어렵다. T.T 한번 만들어 여러 디바이스에 홗용하고 싶다. 인기 순위에서는 충분히 개발할만한 단계에 와 있는 것 같음 ^^; 게임 제작에 적합한 언어의 특징 - 속도? 확장성? 기본 제공 라이브러리? 핵심적인 부분의 최적화, 확장성 그리고 게임제작의 용이성이 중요! Mono Framework의 움직임에 관심을 가져야 함 - XNA로 개발한 게임을 아이폰, 안드로이드에 포팅할 수 있게 됨 - Mono(iOS, Android) + XNA Touch 조합
  • 8.
  • 10.
    Load Initialize Content XNA Framework = API + Application Model Update Draw Unload End Content
  • 11.
    XNA Framework GameLoop Example public class Game1 : Microsoft.Xna.Framework.Game { Initialize, LoadContent는 최초 1번만 호출 SpriteBatch spriteBatch; Update/Draw 는 매 frame 당 호출 public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Input / Network / Sound 처리 모듈은 Update에 위치 } Protected override void Update(GameTime gameTime) Draw는 렌더링과 관련된 리소스만 처리되어야 함 { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } }
  • 12.
    XNA Framework TextureExample public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D m_ChickenTexture; protected override void LoadContent() 주의점 : 코드에서 Load시 파일명은 쓰지 않음 { spriteBatch = new SpriteBatch(GraphicsDevice); m_ChickenTexture = Content.Load<Model>("chicken"); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); 주의점 : 반드시 begin, end 사이에 그려야 함 spriteBatch.Draw(m_ChickenTexture, new Rectangle(0, 0, 480, 800), Color.White); spriteBatch.End(); base.Draw(gameTime); } }
  • 13.
    XNA Framework InputExample Xbox 360 Controllers (Xbox/Windows) Keyboard (Xbox/Windows/Windows phone 7 Series) GamePadState state = GamePad.GetState(PlayerIndex.One); if (state.Buttons.A == ButtonState.Pressed) {} Touch API if (state.ThumbSticks.Left.X > 0.0f) {} 동시에 최대 4개의 Touch Input이 지원 KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Left) == true) 자동으로 회전 및 해상도를 인식하여 처리 {} 개발자가 인식 모듈을 재정의할 수 있음 TouchCollection touches = TouchPanel.GetState(); if (touches.Count > 0) { Sensor API (짂동, 가속도 센서) switch (touches[0].State) { case TouchLocationState.Moved: 진동 강도 및 지속 시간 설정 가능 float touchX = touches[0].Position.X; float touchY = touches[0].Position.Y; break; case TouchLocationState.Pressed: break; } }
  • 14.
    Cross Platform InputAPI Sensors Xbox 360 Controllers (Xbox/Windows) Location Keyboard Accelerometer (Xbox/Windows/Windows phone 7 Series) Vibration Touch API Available across platforms for portability (fewer #ifdefs) Four points on Windows phone 7 Series and Windows Orientation and resolution aware
  • 15.
    XNA Framework SoundExample Content Processor을 Song에서 SoundEffect로 변경 Sound제어를 위해 반드시 Instance를 만들어야 함. public class Game1 : Microsoft.Xna.Framework.Game { SoundEffectInstance instance; SoundEffect m_BackMusic; protected override void LoadContent() { m_BackMusic = Content.Load<SoundEffect>("Music"); instance = m_BackMusic.CreateInstance(); } protected override void Update(GameTime gameTime) { instance.Play(); instance.Pause(); instance.Stop(); base.Update(gameTime); } }
  • 16.
    XNA Framework CollisionExample 2D에서는 Rectangle을 주로 사용 protected override void Update(GameTime gameTime) 3D에서는 BoundingSphere 및 Box를 사용 { Rectangle playerRect = new Rectangle(0, 0, 100, 100); 모두 일관된 인터페이스를 제공 Rectangle enemyRect = new Rectangle(0,0,50,50); if (playerRect.Intersects(enemyRect) == true) { } BoundingBox playerBox = new BoundingBox(new Vector3(0,0,0), new Vector3(1,1,1)); BoundingBox enemyBox = new BoundingBox(); if (playerBox.Intersects(enemyBox) == true) { } BoundingSphere playerSphere = new BoundingSphere(new Vector3(0, 0, 0), 10.0f); BoundingSphere enemySphere = new BoundingSphere(); if (playerSphere.Intersects(enemySphere) == true) { } base.Update(gameTime); }
  • 17.
    XNA Framework 2DAnimation Example Update 문에서 선택되어야 될 frame 계산 int frameCount = 0; SpriteBatch의 총 8개의 draw 함수 중 1장의 이미지에서 int frameTick = 0; Texture2D m_Run; // 이미 로딩되었다고 가정 sourceRect를 선택할 수 있는 함수 선택 public override void Update(GameTime gameTime) { const int maxiumAnimationTick = 100; const int maxiumFrame = 4; if (++frameTick > maxiumAnimationTick) { frameTick = 0; if (++frameCount >= maxiumFrame) frameCount = 0; } base.Update(gameTime); } public override void Draw(GameTime gameTime) { spriteBatch.Begin(); Rectangle playerRect = new Rectangle(0, 0, 96, 96); spriteBatch.Draw(m_Run, playerRect, new Rectangle(96 * frameCount, 0, 96, 96), Color.White, 0, Vector2.Zero, SpriteEffects.None, 0); spriteBatch.End(); }
  • 18.
    3D Model drawExample Model testModel = Content.Load<Model>("Cube_A001_View_1x1x1"); X, FBX 파일이 사용됨 (텍스쳐 포함) Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, -120), 3D 이기 때문에 View, Projection 행렬 설정이 필요 new Vector3(0, 0, 0), Vector3.Up); BasicEffect를 통해 draw Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 1000); // Draw the background. GraphicsDevice.Clear(Color.Black); Matrix[] boneTransforms = new Matrix[testModel.Bones.Count]; // Look up combined bone matrices for the entire model. testModel.CopyAbsoluteBoneTransformsTo(boneTransforms); // Draw the model. foreach (ModelMesh mesh in testModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { // 행렬 설정 effect.World = boneTransforms[mesh.ParentBone.Index]; effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); effect.TextureEnabled = true; } mesh.Draw(); }
  • 19.
    3D Model AnimationExample public class Game1 : Microsoft.Xna.Framework.Game { Model testModel; Content Processor를 SkinnedModelProcessor로 선택 AnimationPlayer animationPlayer; protected override void LoadContent() Default Effect를 SkinnedEffect로 선택 { testModel = Content.Load<Model>("chicken"); 에니메이션 제어를 위한 AnimationPlayer Class를 사용 SkinningData skinningData = testModel.Tag as SkinningData; animationPlayer = new AnimationPlayer(skinningData); Clip에 있는 Text 정보로 Animation 선택(ex. WAIT, HOLD) AnimationClip clip = skinningData.AnimationClips["WAIT"]; animationPlayer.StartClip(clip); Update문 에서 Animation Update 함수 호출 } protected override void Update(GameTime gameTime) SkinnedEffect로 Draw { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } protected override void Draw(GameTime gameTime) { // view와 projection 행렬은 기존 예제와 동일 Matrix[] bones = animationPlayer.GetSkinTransforms(); foreach (ModelMesh mesh in testModel.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.SetBoneTransforms(bones); effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); } mesh.Draw(); } }
  • 24.
    ImagineCup, DreamBuildPlay, 인디게임공모전 App Hub Developer Site Naver XNA Café, 제 블로그 Blog(Gomdong.pe.kr). Download Visual Studio 2010 for Windows Phone XNA Game Studio 4.0 for XP