ArrowSkinItem.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. nameLabel:cc.Label,
  29. scoreLabel:cc.Label,
  30. outlineSprite:cc.Node,
  31. lockedSprite:cc.Node,
  32. store:null,
  33. position:0,
  34. store:cc.Node,
  35. },
  36. // LIFE-CYCLE CALLBACKS:
  37. onLoad () {
  38. this.nameLabel = this.node.children[0];
  39. this.scoreLabel = this.node.children[1];
  40. this.outlineSprite = this.node.children[3];
  41. this.lockedSprite = this.node.children[4];
  42. this.node.on('touchend', ()=> {
  43. this.store.onItemClick(this.position);
  44. }, this);
  45. },
  46. start () {
  47. },
  48. init(arrow,selected,store,position){
  49. console.log(arrow);
  50. this.position = position;
  51. this.store = store;
  52. this.nameLabel.getComponent(cc.Label).string = arrow.name;
  53. this.scoreLabel.getComponent(cc.Label).string = arrow.price;
  54. this.outlineSprite.active = selected;
  55. this.lockedSprite.active = arrow.isBought==0;
  56. },
  57. setUnLock(){
  58. this.lockedSprite.active = false;
  59. console.log('unlock');
  60. },
  61. setSelected(selected){
  62. this.outlineSprite.active = selected;
  63. },
  64. isUnLocked(){
  65. return this.lockedSprite.active == false;
  66. },
  67. // update (dt) {},
  68. });