Commit 2f6ddd04 by 李楚霏

调整

parent 554fcf01
...@@ -8,29 +8,22 @@ ...@@ -8,29 +8,22 @@
import clientEvent from "./clientEvent"; import clientEvent from "./clientEvent";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property(cc.Node) @property(cc.Node)
target: cc.Node = null; target: cc.Node = null;
@property
text: string = 'hello';
rigidBody: cc.RigidBody; rigidBody: cc.RigidBody;
motor: cc.MotorJoint; motor: cc.MotorJoint;
collider: cc.CircleCollider; collider: cc.PhysicsPolygonCollider;
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
onLoad () { onLoad () {
this.rigidBody = this.node.getComponent(cc.RigidBody); this.rigidBody = this.node.getComponent(cc.RigidBody);
this.motor = this.node.getComponent(cc.MotorJoint);
// this.motor.connectedBody // this.motor.connectedBody
this.collider =this.node.getComponent(cc.CircleCollider); this.collider =this.node.getComponent(cc.PhysicsPolygonCollider);
const collisionManager = cc.director.getCollisionManager(); const collisionManager = cc.director.getCollisionManager();
collisionManager.enabled = true; collisionManager.enabled = true;
} }
......
...@@ -35,20 +35,20 @@ export default class NewClass extends cc.Component { ...@@ -35,20 +35,20 @@ export default class NewClass extends cc.Component {
this.startPoint = event.getStartLocation(); this.startPoint = event.getStartLocation();
} }
_touchMoveEvent(event: cc.Event.EventTouch) { _touchMoveEvent(event: cc.Event.EventTouch) {
this.points.push(event.getLocation()); // this.points.push(event.getLocation());
if (this.points.length > 20) { // if (this.points.length > 20) {
this.points.shift(); // this.points.shift();
} // }
const averagePoint = new cc.Vec2(0, 0); // const averagePoint = new cc.Vec2(0, 0);
this.points.forEach((point) => { // this.points.forEach((point) => {
averagePoint.x += point.x; // averagePoint.x += point.x;
averagePoint.y += point.y; // averagePoint.y += point.y;
}) // })
averagePoint.multiplyScalar(1 / this.points.length); // averagePoint.multiplyScalar(1 / this.points.length);
const delta = new cc.Vec2(event.getLocation().x - averagePoint.x, event.getLocation().y - averagePoint.y); // const delta = new cc.Vec2(event.getLocation().x - averagePoint.x, event.getLocation().y - averagePoint.y);
let dir = delta; // let dir = delta;
// let dir = event.getLocation(); let dir = cc.v2( event.getLocation().x - this.startPoint.x, event.getLocation().y - this.startPoint.y);
clientEvent.dispatchEvent('move', dir); clientEvent.dispatchEvent('move', dir);
} }
_touchEndEvent(event: cc.Event.EventTouch) { _touchEndEvent(event: cc.Event.EventTouch) {
......
// 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