For desktop games created with SCL, mostly like you will need to support mouse events. SCL supports two levels of mouse support for 5 different mouse events. The levels are canvas level and sprite level. Canvas level events apply to events anywhere on the canvas. Sprite level events apply to individual sprites. The events supported at both levels are:
create routine as Start set mousedown=OnCanvasMD set mouseup=OnCanvasMU end create routine as OnCanvasMD log("mouse down at "+mouse.x+","+mouse.y) end create routine as OnCanvasMU log("mouse up at "+mouse.x+","+mouse.y) end
As above, to set a mouse event for the canvas, use the set command inside a routine. You can access the location of the mouse click using the build-in variables, mouse.x and mouse.y
To set mouse events for individual sprites, use the same event names in the where clause of the sprite. Each sprite tracks its own mouse events. These events only fire if they occur within the sprite boundary and over an area of the sprite that is not completely transparent (alpha>0).
create sprite from image.png as S1 where x=300 y=300 click=OnSClick end create routine as Start launch S1 end create routine as OnSClick log("mouse up at "+mouse.x+","+mouse.y) log("Sprite loc of mouse up: "+smouse.x+","+smouse.y) end
As above, you can access the x,y location of the click relative to the center of the sprite by using the built-in variables smouse.x smouse.y
You can change an event handler or cancel them altogether by specifying _none as the event handler.
create routine as Example set mousemove=_none update sprite MySprite where click=OnHappyClick update sprite YourSprite where click=_none end
Normally, the top-most sprite will receive the click event. If you would like a sprite to ignore mouse events, thus allowing sprites under it to receive the event, use _ignore for the click event handler. This setting also effects touch events the same way.
create sprite from image.png as S1 where x=300 y=300 click=_ignore end