CocosCreator 물체 이동 제어
properties: {
//
MoveSpeed:0,
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
//
this.left=false;
this.right=false;
this.up=false,
this.down=false;
//
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP,this.onKeyUp,this);
},
start () {
},
update (dt) {
//
//
if(this.left){
this.node.x-=this.MoveSpeed*dt;
}else if(this.right){
this.node.x+=this.MoveSpeed*dt;
}
//
if(this.down){
this.node.y-=this.MoveSpeed*dt;
}else if(this.up){
this.node.y+=this.MoveSpeed*dt;
}
},
onKeyDown(event){
//
switch(event.keyCode){
// A
case cc.macro.KEY.a:
this.left=true;
break;
case cc.macro.KEY.d:
this.right=true;
break;
case cc.macro.KEY.w:
this.up=true;
break;
case cc.macro.KEY.s:
this.down=true;
break;
}
},
onKeyUp(event){
//
switch(event.keyCode){
// A
case cc.macro.KEY.a:
this.left=false;
break;
case cc.macro.KEY.d:
this.right=false;
break;
case cc.macro.KEY.w:
this.up=false;
break;
case cc.macro.KEY.s:
this.down=false;
break;
}
},
8방향의 원리를 실현하려면 차이가 많지 않다. 단지 다른 네 방향으로 이동할 때 x.y축의 좌표를 동시에 바꾸는 것이다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
CocosCreator 입문 튜토리얼의 네트워크 통신1. 서비스 측은 빠른 개발을 위해 초기에 http 통신을 사용할 수 있으며, 그 다음에 웹소켓/socket으로 변경한다. 3. 통신 데이터 형식은 수시로 json이나protocolbuffer로 바뀌어야 할 수도 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.