mirror of
https://gitee.com/devil_root/snake.git
synced 2025-10-10 00:56:28 +00:00
the demo
This commit is contained in:
32
assets/Scripts/camera/camerafollow.ts
Normal file
32
assets/Scripts/camera/camerafollow.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Camera, Component, Node, Vec3, _decorator } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('camerafollow')
|
||||
export class camerafollow extends Component {
|
||||
offset: Vec3 = new Vec3();
|
||||
camera: Camera;
|
||||
|
||||
@property(Node) folNode: Node = null
|
||||
start() {
|
||||
this.camera = this.node.getComponent(Camera);
|
||||
this.gameStart()
|
||||
}
|
||||
|
||||
gameStart() {
|
||||
Vec3.subtract(this.offset, this.node.position, this.folNode.position);
|
||||
}
|
||||
|
||||
_tmpV3: Vec3 = new Vec3()
|
||||
update(deltaTime: number) {
|
||||
// if (Game.Instance.gameState != GameState.GAME_PLAY || Game.Instance.player == null)
|
||||
// return;
|
||||
let targetPos = this._tmpV3;
|
||||
targetPos = Vec3.add(targetPos, this.offset, this.folNode.position);
|
||||
Vec3.lerp(targetPos, this.node.position, targetPos, 0.1);
|
||||
this.node.setPosition(targetPos);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.node.position = new Vec3(0, 0, 0);
|
||||
}
|
||||
}
|
9
assets/Scripts/camera/camerafollow.ts.meta
Normal file
9
assets/Scripts/camera/camerafollow.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ff6d36e8-a512-4150-9bd8-a29280339aa8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user