CSemaphore.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. function CSemaphore(iXPos, iYPos, oSprite, oParentContainer) {
  2. var _oSemaphore;
  3. var _oParentContainer;
  4. var _oReflection;
  5. this._init = function (iXPos, iYPos, oSprite) {
  6. _oSemaphore = this.createSemaphore(iXPos, iYPos, oSprite);
  7. _oReflection = this.createSemaphore(iXPos, iYPos, oSprite);
  8. _oReflection.y += 155;
  9. _oReflection.scaleY = -0.95;
  10. _oReflection.alpha = 0.25;
  11. _oParentContainer.addChild(_oSemaphore);
  12. _oParentContainer.addChildAt(_oReflection, 13);
  13. };
  14. this.createSemaphore = function (iXPos, iYPos, oSprite) {
  15. var oSem;
  16. var oData = {
  17. images: [oSprite],
  18. // width, height & registration point of each sprite
  19. frames: {width: oSprite.width / 2, height: oSprite.height, regX: (oSprite.width / 2) / 2, regY: (oSprite.height) / 2},
  20. animations: {
  21. green: 1,
  22. red: 0
  23. }
  24. };
  25. var oSpriteSheet = new createjs.SpriteSheet(oData);
  26. oSem = createSprite(oSpriteSheet, 1, (oSprite.width / 2) / 2, (oSprite.height) / 2, oSprite.width / 2, oSprite.height);
  27. oSem.stop();
  28. oSem.x = iXPos;
  29. oSem.y = iYPos;
  30. return oSem;
  31. };
  32. this.changeState = function (szState) {
  33. _oSemaphore.gotoAndStop(szState);
  34. _oReflection.gotoAndStop(szState);
  35. };
  36. this.unload = function () {
  37. _oParentContainer.removeChild(_oSemaphore, _oReflection);
  38. };
  39. this.setPositionShadow = function (iX, iY) {
  40. _oReflection.x = iX;
  41. _oReflection.y = iY;
  42. };
  43. this.setPosition = function (iXPos, iYPos) {
  44. _oSemaphore.x = iXPos;
  45. _oSemaphore.y = iYPos;
  46. };
  47. this.setVisible = function (bVal) {
  48. _oSemaphore.visible = bVal;
  49. _oReflection.visible = bVal;
  50. };
  51. this.getX = function () {
  52. return _oSemaphore.x;
  53. };
  54. this.getY = function () {
  55. return _oSemaphore.y;
  56. };
  57. _oParentContainer = oParentContainer;
  58. this._init(iXPos, iYPos, oSprite);
  59. return this;
  60. }