Bullet.ts 728 B

12345678910111213141516171819202122232425262728
  1. import { _decorator, AnimationClip, Component, Node, Sprite, SpriteFrame, Vec3 } from 'cc';
  2. import { Tools } from './Tools/Tools';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Bullet')
  5. export class Bullet extends Component {
  6. start() {
  7. }
  8. init(pos: Vec3, angle: number, frames: SpriteFrame[]) {
  9. this.node.setPosition(pos);
  10. this.node.angle = angle;
  11. if(frames.length === 1){
  12. this.getComponent(Sprite).spriteFrame = frames[0];
  13. return;
  14. }
  15. const ani = Tools.createAnimation(frames, 25, this.node, AnimationClip.WrapMode.Loop);
  16. ani.play();
  17. }
  18. update(deltaTime: number) {
  19. this.node.translate(new Vec3(0, 5));
  20. }
  21. }