x


Swap Custom Cursor for Animated Movie Texture or Sprite Sheet?

I'm trying to make a cursor that is basically the same as the Kinect hand cursor... So when you hover over something, the circle animates around the hand and when it's complete, a function will be called.

I have a sprite sheet prepared, and also a movie texture, but haven't been able to get either to work. Maybe I'm using the wrong approach to begin with (Texture2D seems to cause problems in both cases).

Any clues for me? Here's the code I have that works (just swaps one Texture2D for another). How would I make it show the animated cursor on hover?

var myCursor:Texture2D;
var myCursorHover:Texture2D;
var cursorSizeX: int = 64;  // set to width of your cursor texture
var cursorSizeY: int = 64;  // set to height of your cursor texture
private var cursor:Texture2D;

function Start(){
cursor = myCursor;
Screen.showCursor = false;
}


function OnGUI(){
    GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursor);
}

function cursorHover(){
    cursor = myCursorHover;
}

function cursorRestore(){
    cursor = myCursor;
}
more ▼

asked Mar 15 '12 at 10:49 PM

ShaneTheVeryTall gravatar image

ShaneTheVeryTall
3 3 5 7

Also not working: Droid 4

Mar 15 '12 at 11:34 PM DaveA
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I figured it out. Here is the working code, though I'm sure someone could write a more elegant version. I use a sprite texture that is 55 columns, one row.

var cursorOff:Texture2D;
var cursorOn:Texture2D;
var cursorSizeX: int = 64;  // set to width of your cursor texture
var cursorSizeY: int = 64;  // set to height of your cursor texture

private var hovering : boolean;
private var index : float;
private var v1 : float = 0.0;
private var v2 : float = 0.0;
private var v3 : float = 0.0181818; //width of each sprite by percent of total width
private var v4 : float = 1.0; //height
private var myRect : Rect;


function Start(){
    index = 0;
    hovering = false;
    Screen.showCursor = false;

}

function OnGUI(){

    if(hovering) {
       if(index <= 53){
         updateRect();
         GUI.DrawTextureWithTexCoords(Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY), cursorOn, myRect);
       }else{
         GUI.DrawTextureWithTexCoords(Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursorOn, myRect);
       }
    }else {
       GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursorOff);
    }
}

function cursorHover(){
    hovering = true;
}

function cursorRestore(){
    index = 0;
    hovering = false;
}

function updateRect() {
    index += Time.deltaTime * 25;
    //print(index);
    v1 = (v3 * Mathf.Floor(index));
    myRect = Rect(v1,v2,v3,v4);
}
more ▼

answered Mar 19 '12 at 08:37 PM

ShaneTheVeryTall gravatar image

ShaneTheVeryTall
3 3 5 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2277
x222
x202
x120
x53

asked: Mar 15 '12 at 10:49 PM

Seen: 877 times

Last Updated: Mar 19 '12 at 08:37 PM