attributes_anchor.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { _decorator, Component, EditBox, Vec2 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('attributes_anchor')
  4. export class attributes_anchor extends Component {
  5. @property(EditBox) editBox_x:EditBox = null;
  6. @property(EditBox) editBox_y:EditBox = null;
  7. private call_back:Function = null;
  8. start() {
  9. this.editBox_x.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  10. this.change()
  11. })
  12. this.editBox_y.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  13. this.change()
  14. })
  15. }
  16. initView(call:Function){
  17. this.call_back = call
  18. }
  19. change(){
  20. if(this.call_back!=null){
  21. this.call_back(new Vec2(parseFloat(this.editBox_x.string),parseFloat(this.editBox_y.string)))
  22. }
  23. }
  24. update_att(x:number, y:number) {
  25. if(x==undefined||x==null) {
  26. x = 0.5
  27. }
  28. if(y==undefined||y==null) {
  29. y = 0.5
  30. }
  31. this.editBox_x.string = x.toString()
  32. this.editBox_y.string = y.toString()
  33. }
  34. }