키보드도 되겠다.. 이젠 마우스로 ㄱㄱ
플래시로 자주 만드는 마우스 따라다니는 그림을 한번 만들어 볼까요..
그런 의미에서 이번엔 그림을 바꿔볼까 합니다..
07 Imagine Cup Korea!
마우스 클래스
마우스 정보를 가지고 있습니다.
static IntPtr WindowHandle |
마우스포인터를 지정한다. |
static MouseState GetState() |
마우스상태를 가지고 온다. |
마우스 상태 구조체
마우스 상태정보를 가지고 있습니다.
ButtonState LeftButton |
왼쪽마우스버튼의 버튼상태 |
ButtonState MiddleButton |
중앙마우스버튼의 버튼상태 |
ButtonState RightButton |
오른쪽마우스버튼의 버튼상태 |
int ScrollWheelValue |
휠 의 scroll 정도 |
int X |
X좌표 |
ButtonState XButton1 |
추가마우스1 버튼의 버튼상태 |
ButtonState XButton2 |
추가마우스 2버튼의 버튼상태 |
int Y |
Y좌표 |
버튼정보 열거체
버튼 상태를 표시합니다.
Press |
누르기 |
Release |
떼기 |
소스코드 편집
Game1.cs를 편집한다.
using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; //마우스이벤트를 처리한다. namespace XnaImage { public class Game1 : Microsoft.Xna.Framework.Game { //시스템 private GraphicsDeviceManager graphics; //그래픽스 private ContentManager content; //컨텐츠 private SpriteBatch spBatch; //스프라이트 군 private Texture2D texture; //텍스쳐 //위치 private int x = 100; //X좌표 private int y = 100; //Y좌표 //constructor public Game1() { //그래픽스와 컨텐츠 지정 graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); //Update()를 초당 20회 부르도록 설정 IsFixedTimeStep = true; TargetElapsedTime = new TimeSpan(500000); //50밀리초에 한번 } //초기화 protected override void Initialize() { base.Initialize(); } //그래픽스 컨텐츠 읽어오기 protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { spBatch = new SpriteBatch(graphics.GraphicsDevice); texture = content.Load<Texture2D>("ImagineCup"); //Assent Name지정 } } //그래픽스 컨텐츠 놓아주기 protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) { content.Unload(); } } //업뎃 protected override void Update(GameTime gameTime) { //마우스로 XY좌표 얻어오기 MouseState mouseState = Mouse.GetState(); x=mouseState.X; y=mouseState.Y; //베이스 업뎃 base.Update(gameTime); } //그리기 protected override void Draw(GameTime gameTime) { //배경색 지정 graphics.GraphicsDevice.Clear(Color.Black); //텍스쳐 그림 spBatch.Begin(); Vector2 pos = new Vector2(x-90,y-5); //좌표지정 spBatch.Draw(texture,pos,Color.White); spBatch.End(); //베이스 그리기 base.Draw(gameTime); } } } |
그럼 검은 바탕에 이매진컵 로고가 마우스를 따라 다니는것을 보실 수 있습니다.
그럴듯 한가요? 검은 바탕..ㄷㄷ
'프로그래밍' 카테고리의 다른 글
XNA Framework 정리 (0) | 2009.07.09 |
---|---|
데이타를 스토리지에 저장하기 (0) | 2009.07.09 |
키 이벤트 제어하기 (0) | 2009.07.09 |
이미지에 애니메이션 붙이기 (0) | 2009.07.09 |
이미지 파일 읽어오기 (0) | 2009.07.09 |
댓글