CTurnBoard.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. function CTurnBoard(iXPos, iYPos, oSprite, bLast, oParentContainer) {
  2. var _oTurnBoard;
  3. var _oContainer;
  4. var _aText;
  5. var _oParentContainer = oParentContainer;
  6. this._init = function (iXPos, iYPos, bLast, oSprite) {
  7. _oContainer = new createjs.Container();
  8. _oContainer.x = iXPos;
  9. _oContainer.y = iYPos;
  10. _oParentContainer.addChild(_oContainer);
  11. _aText = new Array();
  12. var oData = {
  13. images: [oSprite],
  14. // width, height & registration point of each sprite
  15. frames: {width: oSprite.width / 2, height: oSprite.height, regX: 0, regY: 0},
  16. animations: {on: [0], off: [1]}
  17. };
  18. var oSpriteSheet = new createjs.SpriteSheet(oData);
  19. _oTurnBoard = createSprite(oSpriteSheet, "off", 0, 0, oSprite.width / 2, oSprite.height);
  20. _oContainer.addChild(_oTurnBoard);
  21. if (!bLast) {
  22. _oContainer.addChild(_aText[0] = this.createText(19, 21, "0", 30, "center"));
  23. _oContainer.addChild(_aText[1] = this.createText(54, 21, "", 30, "center"));
  24. _oContainer.addChild(_aText[2] = this.createText(63, 56, "0", 30, "right"));
  25. } else {
  26. _oContainer.addChild(_aText[0] = this.createText(13, 21, "0", 30, "center"));
  27. _oContainer.addChild(_aText[1] = this.createText(35, 21, "", 30, "center"));
  28. _oContainer.addChild(_aText[2] = this.createText(58, 21, "", 30, "center"));
  29. _oContainer.addChild(_aText[3] = this.createText(63, 56, "0", 30, "right"));
  30. }
  31. };
  32. this.changeState = function (szState) {
  33. _oTurnBoard.gotoAndStop(szState);
  34. };
  35. this.refreshTextByID = function (iID, szText) {
  36. _aText[iID].text = szText;
  37. };
  38. this.createText = function (iX, iY, szText, iSize, szTextAlign) {
  39. var oText = new createjs.Text(szText, iSize + "px " + FONT_GAME, "#ffffff");
  40. oText.textAlign = szTextAlign;
  41. oText.textBaseline = "middle";
  42. oText.x = iX;
  43. oText.y = iY;
  44. return oText;
  45. };
  46. this.unload = function () {
  47. _oParentContainer.removeChild(_oContainer);
  48. };
  49. this.setVisible = function (bVisible) {
  50. _oContainer.visible = bVisible;
  51. };
  52. this._init(iXPos, iYPos, bLast, oSprite);
  53. return this;
  54. }