You are here: Home

XNA Community Thailand

XNA Webboard
ยินดีต้อนรับ, ผู้เยี่ยมชม
กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน.    ลืมรหัสผ่าน?
อยากวิธีทำ textbox ในเกมครับ (1 viewing) (1) ผู้เยี่ยมชม
Go to bottom รายการถูกบันทึก: 0
หัวข้อ: อยากวิธีทำ textbox ในเกมครับ
#1566
csnaijim (สมาชิก)
Senior Boarder
กระทู้: 44
graphgraph
สมาชิกที่ไม่ได้ออนไลน์ Click here to see the profile of this user
อยากวิธีทำ textbox ในเกมครับ 5 เดือน, 3 วัน ที่ผ่านมา กรรม: 0  
ผมอยากได้ textbox เอาไว้ ใส่ชื่อผู้เล่นครับ

ผมเคยเจอในเวปนี้แล้ว แต่ว่ารู้สึกมันจะรับมาเป้นคีย์ เลยอ่าครับ และพอกด Backspace ลบสตริงจนหมด ถ้ากดเลย มันจะ error ทันที

แก้ยังไงดีครับ


โค้ดตัวนี้รู้สึกน่าจะเป็นท่าน mankajib ครับ
private void UpdateKeyboardInput()
{

KeyboardState newKS = Keyboard.GetState();

Keys[] pressedKeys = newKS.GetPressedKeys();

foreach (Keys keyCode in pressedKeys)
{
if (!oldKS.IsKeyDown(keyCode))
if (newKS.IsKeyDown(keyCode))
{
if (keyCode == Keys.Back)
inputStr = inputStr.Remove(inputStr.Length - 1, 1); <<<=== จะดักไงดีครับ Length มันจะกลายเป้น -1 แล้วมันจะ error ทันที
else if (keyCode == Keys.Space)
inputStr = inputStr.Insert(inputStr.Length, " ";
else
inputStr += keyCode.ToString();
}
}
oldKS = newKS;
}
ไฟล์แนบ
ชื่อไฟล์:InputTextboxXNA-3b9860920dfec0bed62177fda207edb4.zip
ขนาดไฟล์:53205
 
การบันทึก การบันทึก  
  The administrator has disabled public write access.
#1570
mankajib (ผู้ดูแลระบบ)
Moderator
กระทู้: 320
graph
สมาชิกที่ไม่ได้ออนไลน์ Click here to see the profile of this user
Re:อยากวิธีทำ textbox ในเกมครับ 5 เดือน, 3 วัน ที่ผ่านมา กรรม: 3  
ลองใช้

try
{
}catch
{
}

ช่วยได้ครับ

หรือจะเช็ค


โค้ด


if (keyCode == Keys.Back)
{
  if(inputStr.Length > 0)
          inputStr = inputStr.Remove(inputStr.Length - 1, 1); 
}

 
การบันทึก การบันทึก  
  The administrator has disabled public write access.
#1577
csnaijim (สมาชิก)
Senior Boarder
กระทู้: 44
graphgraph
สมาชิกที่ไม่ได้ออนไลน์ Click here to see the profile of this user
Re:อยากวิธีทำ textbox ในเกมครับ 5 เดือน, 3 วัน ที่ผ่านมา กรรม: 0  
try
{
}catch
{
}
ใช้ไม่เป้นอ่าครับ เหอๆ

เด๋วลองเอาโค้ดนี้ไปใช้ดูครับ
if (keyCode == Keys.Back)
{
if(inputStr.Length > 0)
inputStr = inputStr.Remove(inputStr.Length - 1, 1);
}
 
การบันทึก การบันทึก  
  The administrator has disabled public write access.
Go to top