03_gameplay/01_player_control
01_player_control
DeviceMotion(设备移动传感器)
cc.systemEvent.on(cc.SystemEvent.EventType.DEVICEMOTION, this.onDeviceMotionEvent, this);
onDeviceMotionEvent (event) {
this._acc.x = event.acc.x;
this._acc.y = event.acc.y;
},
export module SystemEvent {
/** !#en The event type supported by SystemEvent
!#zh SystemEvent 支持的事件类型 */
export class EventType {
/** !#en The event type for press the key down event, you can use its value directly: 'keydown'
!#zh 当按下按键时触发的事件 */
static KEY_DOWN: string;
/** !#en The event type for press the key up event, you can use its value directly: 'keyup'
!#zh 当松开按键时触发的事件 */
static KEY_UP: string;
/** !#en The event type for press the devicemotion event, you can use its value directly: 'devicemotion'
!#zh 重力感应 */
static DEVICEMOTION: string;
}
}
改测试用例只支持移动平台
KeyboardInput(按键触发)
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
onKeyDown (event) {
switch(event.keyCode) {
case cc.KEY.a:
case cc.KEY.left:
console.log('turn left');
this.turnLeft();
break;
case cc.KEY.d:
case cc.KEY.right:
console.log('turn right');
this.turnRight();
break;
}
},
update (dt) {
this.sheep.x += this.speed * dt;
},
turnLeft () {
this.speed = -100;
this.sh