Hướng dẫn Mouse Cursor
Trang 1 trong tổng số 1 trang
Hướng dẫn Mouse Cursor
OK, giờ chúng ta sẽ chơi với Mouse Cursor nào. Nói ra các bạn sẽ khá vất vả nếu đi truy lùng khắp nơi để tìm cách vẽ mouse cursor đấy. Nhưng ở đây các bạn đừng lo, tôi đã tìm mọi cách để đơn giản hóa code rồi ), nó giờ chỉ gói gọn trong 1 file duy nhất là MyHUD.
- Code:
class MyHUD extends HUD;
/***********************************************/
var Vector WorldOrigin;
var Vector WorldDirection;
var Texture2D CursorTexture;
var Vector2D MousePosition;
/**********************************************/
simulated event PostRender()
{
MousePosition = GetMouseCoordinates();
//Deproject the mouse from screen coordinate to world coordinate and store World Origin and Dir.
Canvas.DeProject(MousePosition, WorldOrigin, WorldDirection);
//`log(WorldOrigin @ WorldDirection);
//now you have the world origin and direction vector of the mouse deprojection
//so you can do with it whatever you'd like, such as do a Trace with it to see what the mouse is pointing at
DrawHUD();
}
function vector2D GetMouseCoordinates()
{
local Vector2D mousePos;
local UIInteraction UIController;
local GameUISceneClient GameSceneClient;
UIController = PlayerOwner.GetUIController();
if ( UIController != None)
{
GameSceneClient = UIController.SceneClient;
if ( GameSceneClient != None )
{
mousePos.X = GameSceneClient.MousePosition.X;
mousePos.Y = GameSceneClient.MousePosition.Y;
}
}
return mousePos;
}
function DrawHUD()
{
// local string StringMessage;
// StringMessage = "MouseX" @ MousePosition.X @ "MouseY" @ MousePosition.Y @ "World" @ WorldOrigin @ "WorldDir" @ WorldDirection;
// now draw string with GoldColor color
// Canvas.DrawColor = GoldColor;
// Canvas.SetPos( 10, 10 );
// Canvas.DrawText( StringMessage, false, , , TextRenderInfo );
//Set position for mouse and plot the 2d texture.
Canvas.SetPos(MousePosition.X, MousePosition.Y);
Canvas.DrawTile(CursorTexture, 26 , 26, 360, 360, 25,25);
}
DefaultProperties
{
CursorTexture=Texture2D'DunDefMisc.Cursor_copy'
}
+ Điều cuối cùng cần giải thích là ở DefaultPropertise thôi, DundefMisc.Cursor_copy >>>> DundefMisc là tên packages, còn Cursor_copy là Texture tớ import vào trong packages ấy ( nằm trong Content Browser của Editor UDK ). Tôi có đính kèm file ở dưới, các bạn down về rồi cho vào UDKGame\Content\ rổi bỏ vào thư mục nào đó tùy thích ( riêng tôi tạo 1 thư mục Long_game , sau đó tôi bỏ các packages tôi làm hoặc sưu tầm cho vào đây, để khỏi lẫn lộn với các packages của UDK ko bị rối rắm, Full_Load bạn sẽ thấy toàn bộ các file nằm trong packages đó vì mặc định nó là Unload ).
http://www.mediafire.com/?mlnnjkiozzm
honglong99- Tổng số bài gửi : 24
Join date : 08/07/2010
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|