Making stationary object move with the mouse
by Westwood College Ohare (#0001) · in Torque Game Builder · 05/25/2006 (8:14 pm) · 1 replies
Im trying to make a stationary object rotate in the direction the mouse is pointing and was wondering how i should start. I would like to make a turrent like object rotate and aim where ever the mouse it pointing. And is there a way to change the image of the mouse pointer? Can ne1 help me?
About the author
Torque Owner Anthony Fullmer
When you get that far add this function to your code where you feel is appropriate (i put mine in a separate file named mouseSprite.cs which i had to exec in my main.cs file:
function SceneWindow2D::onMouseMove(%this, %mod, %worldPosition)
{
myCursor.setPosition(%worldPosition);
}
function SceneWindow2D::onMouseLeave(%this, %mod, %worldPosition)
{
Canvas.showCursor();
}
function SceneWindow2D::onMouseEnter(%this, %mod, %worldPosition)
{
Canvas.hideCursor();
}
This will make the sprite follow the mouse cursor, plus act correctly when you enter or leave the game window.
To get your cursor to disappear so the custom cursor is the only one that is visible, add this code to the startGame function of your game.cs file:
// This code will hide your cursor
Canvas.hideCursor();
and, finally, you will want your cursor to reappear when you leave the level, so add this to your game.cs file in your endGame function:
//re-initializes your cursor
Canvas.showCursor();
I hope this helps you out, if you run into any problems let me know!!