Integration recipes
Most apps need one of four patterns. Use MotionSDK.configure(for:) + a small helper from TrikiRecipes.swift — then pollInput every frame.
import VeltoKit
let motion = MotionSDK()
motion.connect() // physical iPhone; see BLE doc for manual bytes
// In your game loop (~60 Hz):
let input = motion.pollInput(deltaTime: dt)
| Recipe | configure(for:) | Helper | Main fields |
|---|---|---|---|
| Pong | .pong | TrikiSimplePong | posX |
| UI / Quiz menu | .menu | TrikiUIPicker | posX, bleButtonClick |
| Dart / pointer | .pointerGame | TrikiSimplePointer, TrikiGameActions | posX, posY, shotTriggered |
| Bowling / gesture | .gestureGame | TrikiSimpleAim, TrikiGameActions | shotTriggered, bleButtonClick |
Deep tuning: GameInput · BLE · Configuration.
1. Pong
motion.configureForPong()
var pong = TrikiSimplePong()
var paddleX = courtWidth / 2
func tick(dt: TimeInterval) {
let input = motion.pollInput(deltaTime: dt)
paddleX = pong.paddleX(
current: paddleX,
input: input,
deltaTime: dt,
courtWidth: courtWidth
)
paddleX = min(max(0, paddleX), courtWidth)
}
Shortcut: map input.posX directly if you do not need adaptive BLE shaping — see Pong example.
2. UI / Quiz menu
Tilt → focus slot · physical button (bytes[1]) → confirm. No hold required.
motion.configureForMenu()
var picker = TrikiUIPicker()
func tick(dt: TimeInterval) {
let input = motion.pollInput(deltaTime: dt)
if picker.tick(input: input, deltaTime: dt, slots: itemCount) {
onActivate(picker.focusIndex)
}
highlightRow(picker.focusIndex)
}
TrikiButtonGate— debounced edge onbleButtonClick(also used insideTrikiUIPicker).- SwiftUI sample: Triki UI (
.trikiUIScreen,preferButtonConfirm: true).
3. Pointer games (Dart)
motion.configureForPointerGame()
var aim = TrikiSimplePointer()
var actions = TrikiGameActions()
var aimX = 0.5, aimY = 0.5
func tick(dt: TimeInterval) {
let input = motion.pollInput(deltaTime: dt)
(aimX, aimY) = aim.aim(currentX: aimX, currentY: aimY, input: input, deltaTime: dt)
for event in actions.tick(input: input, deltaTime: dt) {
switch event {
case .primedToThrow: showPullBackHint()
case .threw(let power): launchDart(power: power)
case .buttonConfirmed: confirmSelection()
}
}
}
4. Gesture games (Bowling)
motion.configureForGestureGame()
var lateral = TrikiSimpleAim()
var actions = TrikiGameActions()
var aimX = 0.0
func tick(dt: TimeInterval) {
let input = motion.pollInput(deltaTime: dt)
aimX = lateral.step(
current: aimX,
lean: input.sensors.tiltY,
input: input,
deltaTime: dt
)
for event in actions.tick(input: input, deltaTime: dt) {
switch event {
case .threw(let power): rollBall(power: power, lateral: aimX)
case .buttonConfirmed: startTurn() // lobby or between players
default: break
}
}
}
Throws use shotTriggered / gesture pipeline — not the cap button. Button is for confirm only (menu, turn start).
Manual BLE (no connect())
Same recipes; feed bytes yourself:
motion.configureForPong()
motion.enqueueBLE(bytes)
motion.updateFrame(deltaTime: dt)
let input = motion.input