BgScroll.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. export default class ShaderParamComponent extends cc.Component {
  4. private sprite: cc.Sprite = null;
  5. private _material: cc.Material = null;
  6. private _start = 0;
  7. @property({ displayName: "速度" })
  8. private speed: number = 1;
  9. onLoad() {
  10. this.sprite = this.getComponent(cc.Sprite);
  11. if (this.sprite) {
  12. this._material = this.sprite.getMaterial(0);
  13. }
  14. this.initParams()
  15. }
  16. private initParams() {
  17. if (this.sprite && this._material && this.speed) {
  18. this._material.setProperty("speed", this.speed)
  19. }
  20. }
  21. protected update(dt) {
  22. // if (this.sprite) {
  23. // this._material = this.sprite.getMaterial(0);
  24. // }
  25. if (this.node.active && this._material) {
  26. if (this._material.getProperty("time", 0) != undefined) {
  27. this._material.setProperty('time', this._start);
  28. this._start += dt;
  29. }
  30. }
  31. }
  32. }