37 lines
928 B
TypeScript
37 lines
928 B
TypeScript
import { _decorator, Component, Node } from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/// 按钮按下效果 在按下时 向下移动一个坐标
|
|
@ccclass('ButtonDown')
|
|
export class ButtonDown extends Component {
|
|
start() {
|
|
this.node.on(Node.EventType.TOUCH_START,this.onTouchStart,this);
|
|
this.node.on(Node.EventType.TOUCH_END,this.onTouchEnd,this);
|
|
this.node.on(Node.EventType.TOUCH_CANCEL,this.onTouchCancel,this);
|
|
}
|
|
|
|
onTouchStart(event:Event){
|
|
const pos = this.node.getPosition();
|
|
pos.y -= 1;
|
|
this.node.setPosition(pos);
|
|
}
|
|
|
|
onTouchEnd(event:Event){
|
|
const pos = this.node.getPosition();
|
|
pos.y += 1;
|
|
this.node.setPosition(pos);
|
|
}
|
|
|
|
onTouchCancel(event:Event){
|
|
const pos = this.node.getPosition();
|
|
pos.y += 1;
|
|
this.node.setPosition(pos);
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
|
|
}
|
|
}
|
|
|
|
|