attributes_anchor.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, Component, EditBox, Vec2, Node } 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. @property(Node) btn_set:Node = null;
  8. private call_back:Function = null;
  9. start() {
  10. this.editBox_x.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  11. this.change()
  12. })
  13. this.editBox_y.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  14. this.change()
  15. })
  16. this.btn_set.on(Node.EventType.TOUCH_END, ()=>{
  17. })
  18. }
  19. initView(call:Function){
  20. this.call_back = call
  21. }
  22. change(){
  23. if(this.call_back!=null){
  24. this.call_back(new Vec2(parseFloat(this.editBox_x.string),parseFloat(this.editBox_y.string)))
  25. }
  26. }
  27. update_att(x:number, y:number) {
  28. if(x==undefined||x==null) {
  29. x = 0.5
  30. }
  31. if(y==undefined||y==null) {
  32. y = 0.5
  33. }
  34. this.editBox_x.string = x.toString()
  35. this.editBox_y.string = y.toString()
  36. }
  37. }