Item.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Color, Component, Label, Node, Sprite,tween,Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. class BindTarget{
  4. color : Color
  5. }
  6. @ccclass('Item')
  7. export class Item extends Component {
  8. numType:number;
  9. row:number;
  10. col:number;
  11. //是否已经处于变色区域内
  12. isLock:boolean;
  13. start() {
  14. }
  15. init(_numType,_row,_col){
  16. this.numType=_numType
  17. this.row=_row
  18. this.col=_col
  19. this.showUI()
  20. }
  21. changeType(_numType){
  22. this.numType=_numType
  23. this.showUI()
  24. }
  25. showUI(){
  26. // let colorArr=[Color.RED,Color.GREEN,Color.BLUE,Color.YELLOW,Color.GRAY,Color.WHITE]
  27. let colorArr=[new Color(0,192,196,255),new Color(112,196,0,255),new Color(255,4,112,255),new Color(255,221,0,255)]
  28. let label=this.node.getChildByName("Label").getComponent(Label)
  29. label.string="";//this.numType+"|"+this.row+","+this.col
  30. this.node.getChildByName("SpriteSplash").getComponent(Sprite).color=colorArr[this.numType]
  31. this.node.scale=new Vec3(0.7,0.7,1)
  32. tween(this.node)
  33. .to(0.2, {
  34. scale: new Vec3(1, 1, 1), // 缩放缓动
  35. }
  36. )
  37. .start();
  38. }
  39. update(deltaTime: number) {
  40. }
  41. }