Monday, 9 April 2012

Object List - Picking Sprites

Now we have a couple of objects to play with, we can extend out pointer use to pick them up and move them about - one of the main features of the game.

We already have some information printed to the screen, showing the screen size and pointer position, now we are going to add some more to help with the picking up function.

Immediately after the following lines in the do/loop;

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

add the following lines;

printc( "Sprite: ")
print( str( getSpriteHit( getPointerX() , getPointerY() )))

This introduces another new command getSpriteHit(), which returns the sprite reference of any sprite at the position specified.  In this case the position specified is the current position of the pointer returned from getPointerX() and getPointerY().

Compile and run the project and now as you move the pointer over a sprite, it's reference will be shown at the top of the screen.  If there is no sprite at the position of the pointer is will show 0

At last I get to use the finger we created right back at the start.

If you extend the panel - yes that still works - and move the pointer over that, you will also notice it returns the references of the sprites used to make up the panel as well.
So now we have a way to identify which sprite is at the cursor position.

No comments:

Post a Comment