SCL™ supports many kinds of touch events across all touch-enabled devices. Touch events can be relative to the whole canvas or to a particular sprite, depending on the type of event. The table below illustrates.
Canvas Touch | Sprite Touch |
---|---|
|
|
Touch events that apply to the whole canvas are set inside a routine using a "set" command.
For example, set touchstart=OnTouchStart,
where OnTouchStart is a routine.
Touch events for a particular sprite
are set inside a sprite definition inside the where clause.
For example,
create routine as Start
launch MySprite
end
create sprite from 2.png as MySprite
where x=400 y=300 center=50,50 size=3
touchstart=OnSpriteTouchStart
touchend=OnSpriteTouchEnd
swipeup=OnSpriteSwipeUp
end
create routine as OnSpriteTouchStart
insert into _sprite where alt=(sub create rotation end)
end
create routine as OnSpriteTouchEnd
remove from _sprite where type=_all
end
create routine as OnSpriteSwipeUp
insert into _sprite where alt=(sub
create slide where direction=90
end)
end
In the example above, after you swipe upwards, you'll need to push the "Run" button again
to reset the example.
Some touch events on sprites can be changed in a routine using update.
For example:
update sprite MySprite where touchdrag=true
update sprite MySprite where swipeup=OnSwipeUp
update sprite MySprite where swipedown=_none
update sprite MySprite where swipeleft=OnSwipeLeft
update sprite MySprite where swiperight=_none
Notice how "_none" removes an event handler.
touchdrag is a sprite property that allows a finger on the screen
to drag a sprite. This property takes a true or false value.
Enjoy this example code:
create sprite from 2.png as s1
where center=50,50 x=260 y=300
touchdrag=true
end
create sprite from 4.png as s2
where center=50,50 x=250 y=320
touchdrag=true
end
create sprite from 8.png as s3
where center=90,90 x=230 y=290
touchdrag=true
end
create routine as Start
launch s1
launch s2
launch s3
end
On a touch-enabled device, you can drag sprites by touching their visible portion.
_touch is a special variable that gives you values related to the most recent touch event. What the values mean vary depending on the most recent type of touch event.