Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Nhận biết Keyboard trong Runtime với lập trình C#

    _Em viết thử xí xem , mấy đại ca thấy gì không hay thì bỏ qua nha ; em mới học C# thôi [IMG]images/smilies/dont_know.gif[/IMG]

    _Tạo một class ứng dụng vào một chương trình, dùng để nhận biết key được ấn khi đang làm việc khác. Ví dụ : Class dưới đây minh họa khi chơi game thì kiểm tra xem nút được Press hay release [IMG]images/smilies/biggrin.png[/IMG]


    Mã:
    #region Using Statementsusing 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;#endregion public class GameKeyTestClass : Microsoft.Xna.Framework.Game{    GraphicsDeviceManager graphics;    ContentManager content;     KeyboardState oldState;     public GameKeyTestClass ()    {        graphics = new GraphicsDeviceManager( this );        content = new ContentManager( Services );         oldState = Keyboard.GetState();    }     protected override void Initialize()    {         base.Initialize();    }     protected override void LoadGraphicsContent( bool loadAllContent )    {        if (loadAllContent)        {         }     }     protected override void UnloadGraphicsContent( bool unloadAllContent )    {        if (unloadAllContent == true)        {            content.Unload();        }    }     protected override void Update( GameTime gameTime )    {        // Mặc định thoát game trong Xbox và Win        if (GamePad.GetState( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed)            this.Exit();         UpdateInput();         base.Update( gameTime );    }     private void UpdateInput()    {        KeyboardState newState = Keyboard.GetState();         // Kiểm tra xem Space có bị Press không        if (newState.IsKeyDown( Keys.Space ))        {            // Key Space được Press        }        // Nếu không thì kiểm tra xem nó có Down trước đó không?        // có thẻ release sau đó        else if (oldState.IsKeyDown( Keys.Space ))        {           // Space bị Release rồi        }         oldState = newState;    }     protected override void Draw( GameTime gameTime )    {        graphics.GraphicsDevice.Clear( Color.CornflowerBlue );         base.Draw( gameTime );    }}

  2. #2
    Ngày tham gia
    Sep 2015
    Đang ở
    24 Rạch Bùng Binh , P10,Q3 , HCM
    Bài viết
    0
    Hình như là phải cài XNA của Microsoft đó bạn. Chi tiết ở bài của anh nhc1987 "XNA cơ bản": XNA cơ bản

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •