Friday, 6 April 2012

Reading The Pointer

With the image loaded, the sprite created and the resolution set, all that is needed to make our finger pointer move is to read the current pointer position and transfer it to the sprite.

The commands getPointerX() and getPointerY() are used to read the pointer X and Y positions respectively and these can be inserted straight into the existing setSpritePosition() command in our project.

setSpritePosition( spriteRef , getPointerX() , getPointerY() )

Currently this is called just once at the start. In order to make the pointer move continually, this needs to be transferred to inside the do/loop section so that it is done in every frame.
Finally we can replace the lines which print the Virtual Resolution (which are no longer needed as this is now the same as the physical resolution);

printc( "Virtual: " )
print( str( virtWidth# ) + " x " + str( virtHeight# ) )

with ones which show the position of the pointer;

printc( "Pointer: " )
print( str( getPointerX() ) + " x " + str( getPointerY() ) )

The project now looks like this.
Now within windows , whenever the pointer is over the output window, the finger will follow it and the position will be shown in text at the top of the screen.
Remember, this is purely for my screen grabs and will not be present in the final project.

Preparations are complete, now the project can begin.

No comments:

Post a Comment