This example uses the BLUE and PURPLE blocks from the collisions example, so make sure to put them in the media folder before trying it...
rem A Wizard Did It!
SetDisplayAspect( 4.0/3.0 )
SetVirtualResolution ( 480, 480 )
SetSyncRate(60,1)
// create the sprite
CreateSprite ( 1, 0 )
SetSpritePosition ( 1, 130, 200 )
// add individual images into an animation list
AddSpriteAnimationFrame ( 1, LoadImage ( "blue.png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "purple.png" ) )
// main loop
do
if GetPointerPressed() = 1
if GetPointerX() > 130 and GetPointerX() < 194
if GetPointerY() > 200 and GetPointerY() < 264
if GetSpriteCurrentFrame(1) = 1
SetSpriteFrame(1,2)
else
SetSpriteFrame(1,1)
endif
endif
endif
endif
Sync()
loop
As you can see this is pretty straight forward.
First we detect the mouse click...
if GetPointerPressed() = 1
Then we detect the X position of the pointer, and limit it to the size and location of the sprite...
if GetPointerX() > 130 and GetPointerX() < 194
Then we do the same for the Y coordinate...
if GetPointerY() > 200 and GetPointerY() < 264
If all of those are true, then we know they are clicking on the sprite, so we then detect the sprite's current frame...
if GetSpriteCurrentFrame(1) = 1
And set the frame accordingly...
SetSpriteFrame(1,2)
else
SetSpriteFrame(1,1)
Here is another example that uses 2 sprites that are sharing the same location.
This starts out with one visible and the other invisible.
It checks for the click in the proper locaton like before, but this time instead of changing frames it sets the visibility on both sprites...
rem A Wizard Conjured It!
SetDisplayAspect( 4.0/3.0 )
SetVirtualResolution ( 480, 480 )
SetSyncRate(60,1)
// create the sprite
CreateSprite ( 1, 0 )
SetSpritePosition ( 1, 130, 200 )
SetSpriteVisible(1,1)
CreateSprite ( 2, 0 )
SetSpritePosition ( 2, 130, 200 )
SetSpriteVisible(2,0)
// add individual images to the sprites
AddSpriteAnimationFrame ( 1, LoadImage ( "blue.png" ) )
AddSpriteAnimationFrame ( 2, LoadImage ( "purple.png" ) )
// main loop
do
if GetPointerPressed() = 1
if GetPointerX() > 130 and GetPointerX() < 194
if GetPointerY() > 200 and GetPointerY() < 264
if GetSpriteVisible(1) = 1
SetSpriteVisible(1,0)
SetSpriteVisible(2,1)
else
SetSpriteVisible(1,1)
SetSpriteVisible(2,0)
endif
endif
endif
endif
Sync()
loop
Hope this helps.
Have fun