XNA遊戲 各種輸入測試 上

2021-09-21 11:21:59 字數 4465 閱讀 7838

測試xna遊戲中鍵盤輸入,觸控輸入,按鈕輸入

game1.cs

using system;  

using system.collections.generic;  

using system.linq;  

using microsoft.xna.framework;  

using microsoft.xna.framework.audio;  

using microsoft.xna.framework.content;  

using microsoft.xna.framework.gamerservices;  

using microsoft.xna.framework.graphics;  

using microsoft.xna.framework.input;  

using microsoft.xna.framework.input.touch;  

using microsoft.xna.framework.media;  

using inputhandlerdemo.inputs;  

namespace inputhandlerdemo  

protected override void initialize()  

/// 

<

summary

>

/// 新增各種輸入方式  

/// 

summary

>

private void addinputs()  

protected override void loadcontent()  

protected override void unloadcontent()  

protected override void update(gametime gametime)  

protected override void draw(gametime gametime)  

}  } action.cs 遊戲操作的型別

namespace inputhandlerdemo  

} 下面是輸入的操作的封裝類

gameinput.cs

using system;  

using system.collections.generic;  

using microsoft.xna.framework;  

using microsoft.xna.framework.input;  

using microsoft.xna.framework.input.touch;  

namespace inputhandlerdemo.inputs  

return inputs[theaction];  

}  public void beginupdate()  

public void endupdate()  

public bool isconnected(playerindex theplayer)  

public bool ispressed(string theaction)  

return inputs[theaction].ispressed(playerindex.one);  

}  /// 

<

summary

>

/// 判斷單擊的狀態  

/// 

summary

>

/// 

<

param

name

="theaction"

>

動作param

>

/// 

<

param

name

="theplayer"

>

玩家param

>

/// 

<

returns

>

returns

>

public bool ispressed(string theaction, playerindex theplayer)  

return inputs[theaction].ispressed(theplayer);  

}  public bool ispressed(string theaction, playerindex? theplayer)  

return ispressed(theaction, (playerindex)theplayer);  

}  public bool ispressed(string theaction, playerindex? theplayer, out playerindex thecontrollingplayer)  

if (

theplayer

== null)  

if (ispressed(theaction, playerindex.two))  

if (ispressed(theaction, playerindex.three))  

if (ispressed(theaction, playerindex.four))  

thecontrollingplayer

= playerindex

.one;  

return false;  

}  thecontrollingplayer

= (playerindex)theplayer;  

return ispressed(theaction, (playerindex)theplayer);  

}  public void addgamepadinput(string theaction, buttons thebutton,  

bool isreleasedpreviously)  

public void addtouchtapinput(string theaction, rectangle thetoucharea,  

bool isreleasedpreviously)  

public void addtouchslideinput(string theaction, input.direction thedirection,  

float slidedistance)  

public void addkeyboardinput(string theaction, keys thekey,  

bool isreleasedpreviously)  

public void addtouchgestureinput(string theaction, gesturetype thegesture,  

rectangle therectangle)  

public void addaccelerometerinput(string theaction, input.direction thedirection,  

float tiltthreshold)  

public vector2 currentgestureposition(string theaction)  

public vector2 currentgesturedelta(string theaction)  

public vector2 currentgestureposition2(string theaction)  

public vector2 currentgesturedelta2(string theaction)  

public point currenttouchpoint(string theaction)  

return new point((int)currentposition.value.x, (int)currentposition.value.y);  

}  public vector2 currenttouchposition(string theaction)  

return (vector2)currenttouchposition;  

}  public float currentgesturescalechange(string theaction)  

public vector3 currentaccelerometerreading(string theaction)  

}  } gesturedefinition.cs

using system;  

using microsoft.xna.framework;  

using microsoft.xna.framework.input.touch;  

namespace inputhandlerdemo.inputs  

public gesturedefinition(gesturesample thegesturesample)  

}  } 

《XNA遊戲開發》簡介

一 xna簡介 xna是基於directx的遊戲開發環境。以c 為開發語言 以 net framework 為基礎 並加入遊戲應用所需之函式庫所構成的 xna framework 可開發xna for windows phone遊戲,xbox遊戲,pc遊戲等。二 xna versions xna g...

XNA 垮平台遊戲開發框架

引用自 microsoft xna homepage gdc於日前正式結束,我們聽到看到的是微軟不停的宣傳xna開發工具.它究竟是什麼?讓我們來初步了解一下!xna是微軟推出的所謂 通用軟體開發平台 它的目標是讓遊戲開發過程更加輕鬆簡單。xna中,x代表微軟掌握的技術資源,directx和xbox ...

為 Xna 遊戲建立漂亮的字型

一般情況下,xna使用預處理生成的貼圖繪製字型。貼圖的生成一般有幾種方法 通過向content project中新增sprite font檔案,讓系統自動生成貼圖字型。這是最簡單的一種方法,同時也是最難看的一種方法。bitmap font maker 是xna creators club onlin...