Keywords:

_touch _none

Touch Events

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
  • touchstart
  • touchend
  • touchmove
  • swipeup
  • swiperight
  • swipedown
  • swipeleft
  • pinch
  • pivot
  • touchstart
  • touchend
  • touchdrag
  • swipeup
  • swiperight
  • swipedown
  • swipeleft

Canvas Touch Events

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.

Sprite Touch Events

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 on a sprite

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 variable

_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.

_touch.x
The x position of the touch on the canvas. This is synonmous with _touch.x2
_touch.y
The y position of the touch on the canvas. This is synonmous with _touch.y2
_touch.x1
The x position of the previous touch on the canvas.
_touch.y1
The y position of the previous touch on the canvas.
_touch.x2
The x position of the touch on the canvas. This is synonmous with _touch.x
_touch.y2
The y position of the touch on the canvas. This is synonmous with _touch.y
_touch.distance
The distance between the last two touch positions if a touch was dragged.
_touch.distancex
The horizontal distance between the last two touch positions if a touch was dragged.
_touch.distancey
The vertical distance between the last two touch positions if a touch was dragged.
_touch.change
For pivot and pinch events, _touch.change returns angle and pixel change respectively.
_touch.percent
For pinch events, returns percent change relative to start position of pinch fingers.
_touch.angle
For pivot events, returns the angle between 2 touch positions.
_touch.size
For pinch events, returns the new size of the current sprite being updated.