CCell.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function CCell(iX, iY, iRegY, oSprite, oParentContainer) {
  2. var _oCell;
  3. var _iRow;
  4. var _iCol;
  5. var _oParentContainer = oParentContainer;
  6. this._init = function (iX, iY, iRegY, oSprite) {
  7. _oCell = createBitmap(oSprite);
  8. _oCell.x = iX;
  9. _oCell.y = iY;
  10. var oData = {
  11. images: [oSprite],
  12. // width, height & registration point of each sprite
  13. frames: {width: oSprite.width / 2, height: oSprite.height, regX: (oSprite.width / 2) / 2, regY: (oSprite.height / 2) + iRegY},
  14. animations: {normal: [0], complete: [1]}
  15. };
  16. var oSpriteSheet = new createjs.SpriteSheet(oData);
  17. _oCell = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 2, (oSprite.height / 2) + iRegY, oSprite.width / 2, oSprite.height);
  18. _oCell.stop();
  19. _oParentContainer.addChild(_oCell);
  20. };
  21. this.setPosition = function (iX, iY) {
  22. _oCell.x = iX;
  23. _oCell.y = iY;
  24. };
  25. this.getY = function () {
  26. return _oCell.y;
  27. };
  28. this.getX = function () {
  29. return _oCell.x;
  30. };
  31. this.setRow = function (iVal) {
  32. _iRow = iVal;
  33. };
  34. this.setCol = function (iVal) {
  35. _iCol = iVal;
  36. };
  37. this.getRow = function () {
  38. return _iRow;
  39. };
  40. this.getCol = function () {
  41. return _iCol;
  42. };
  43. this.setRegY = function (iVal) {
  44. _oCell.regY = iVal;
  45. };
  46. this.changeState = function (iVal) {
  47. _oCell.gotoAndStop(iVal);
  48. };
  49. this.getSprite = function () {
  50. return _oCell;
  51. };
  52. this.getRegY = function () {
  53. return _oCell.regY;
  54. };
  55. this.setVisible = function (bVal) {
  56. _oCell.visible = bVal;
  57. };
  58. this.getChildIndex = function () {
  59. return _oParentContainer.getChildIndex(_oCell);
  60. };
  61. this.setChildIndex = function (iVal) {
  62. _oParentContainer.setChildIndex(_oCell, iVal);
  63. };
  64. this.unload = function () {
  65. _oParentContainer.removeChild(_oCell);
  66. };
  67. this._init(iX, iY, iRegY, oSprite);
  68. return this;
  69. }