Commit 2f6ddd04 by 李楚霏

调整

parent 554fcf01
......@@ -8,29 +8,22 @@
import clientEvent from "./clientEvent";
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property(cc.Node)
target: cc.Node = null;
@property
text: string = 'hello';
rigidBody: cc.RigidBody;
motor: cc.MotorJoint;
collider: cc.CircleCollider;
collider: cc.PhysicsPolygonCollider;
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.rigidBody = this.node.getComponent(cc.RigidBody);
this.motor = this.node.getComponent(cc.MotorJoint);
// this.motor.connectedBody
this.collider =this.node.getComponent(cc.CircleCollider);
this.collider =this.node.getComponent(cc.PhysicsPolygonCollider);
const collisionManager = cc.director.getCollisionManager();
collisionManager.enabled = true;
}
......
......@@ -35,22 +35,22 @@ export default class NewClass extends cc.Component {
this.startPoint = event.getStartLocation();
}
_touchMoveEvent(event: cc.Event.EventTouch) {
this.points.push(event.getLocation());
if (this.points.length > 20) {
this.points.shift();
}
const averagePoint = new cc.Vec2(0, 0);
this.points.forEach((point) => {
averagePoint.x += point.x;
averagePoint.y += point.y;
})
averagePoint.multiplyScalar(1 / this.points.length);
// this.points.push(event.getLocation());
// if (this.points.length > 20) {
// this.points.shift();
// }
// const averagePoint = new cc.Vec2(0, 0);
// this.points.forEach((point) => {
// averagePoint.x += point.x;
// averagePoint.y += point.y;
// })
// averagePoint.multiplyScalar(1 / this.points.length);
const delta = new cc.Vec2(event.getLocation().x - averagePoint.x, event.getLocation().y - averagePoint.y);
let dir = delta;
// let dir = event.getLocation();
// const delta = new cc.Vec2(event.getLocation().x - averagePoint.x, event.getLocation().y - averagePoint.y);
// let dir = delta;
let dir = cc.v2( event.getLocation().x - this.startPoint.x, event.getLocation().y - this.startPoint.y);
clientEvent.dispatchEvent('move', dir);
}
}
_touchEndEvent(event: cc.Event.EventTouch) {
this.points = [];
}
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
rigidBody: cc.RigidBody;
collider: cc.PhysicsPolygonCollider;
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.rigidBody = this.node.getComponent(cc.RigidBody);
// this.motor.connectedBody
this.collider =this.node.getComponent(cc.PhysicsPolygonCollider);
const collisionManager = cc.director.getCollisionManager();
collisionManager.enabled = true;
}
start () {
}
update (dt) {
this.rigidBody.angularVelocity = 200;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment