Chủ đề: Thắc mắc làm game XNA C#
-
21-05-2015, 11:37 AM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Thắc mắc làm game XNA C#
Em mới mày mò làm game bằng XNA , đã vế được nhân vật(thực ra là lấy ảnh[IMG]images/smilies/redface.png[/IMG]) nhưng khi em đặt thuộc tính để chạy ảnh không đi quá màn hình , thì Y chỉ được thế này, và tọa độ X cũng thế
Code của em là :
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
myTexture = Content.Load<Texture2D>("Running");
myRectangle = new Rectangle(100, 100, 250, 250);
screenHeight = GraphicsDevice.Viewport.Height;
screenWidth = GraphicsDevice.Viewport.Width;
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// Get the state of keyboard
KeyboardState keyState = Keyboard.GetState();
if(keyState.IsKeyDown(Keys.Right))
{
myRectangle.X += 3;
}
if (keyState.IsKeyDown(Keys.Left))
{
myRectangle.X -= 3;
}
if (keyState.IsKeyDown(Keys.Up))
{
myRectangle.Y -= 3;
}
if (keyState.IsKeyDown(Keys.Down))
{
myRectangle.Y += 3;
}
// Make conditions to make sure the icon doesn't go out of Device range
if (myRectangle.X <= 0)
{
myRectangle.X = 0;
}
if (myRectangle.X + myTexture.Width>= screenWidth)
{
myRectangle.X = screenWidth - myTexture.Width ;
}
if (myRectangle.Y <= 0)
{
myRectangle.Y = 0;
}
if (myRectangle.Y + myTexture.Height>= screenHeight)
{
myRectangle.Y = screenHeight - myTexture.Height ;
}
// TODO: Add your update logic here
base.Update(gameTime);
}
--- Anh chị cho em biết lí do và sửa thế nào ạ ?View more random threads:
- Hướng dẫn làm chương trình đố vui nho nhỏ
- Hoi về code độ sáng tối camare bằng c#
- Code đổi số thành chữ trong C#
- Xử lý String và Regular Expressions (Regex Class) Trong C#
- Xây dựng website đa ngôn ngữ trong asp.net
- Tạo phím nóng trong dotnet không thèm đụng hook
- Hướng dẫn tạo Form Đăng Ký và Đăng Nhập - part 1
- Một số thao tác quậy trên WinForm C#
- hoa tươi giá rẻ tại đà nẵng ,địa chỉ shop hoa toàn quốc
- Phân Quyền (Phần I : Phân quyền trên Menu)
Pallet nhựa Lâm Đồng giải pháp hoàn hảo cho nhà kho Pallet nhựa Lâm Đồng là một giải pháp đa năng và hiệu quả trong việc vận chuyển và lưu trữ hàng hóa. Trong đó, pallet nhựa Lâm Đồng không chỉ đáp...
Pallet nhựa Lâm Đồng giải pháp...