CBallTarget.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function CBallTarget(iXPos, iYPos, oSprite, oParentContainer) {
  2. var _oTarget;
  3. var _oParentContainer = oParentContainer;
  4. this._init = function (iXPos, iYPos, oSprite) {
  5. var oData = {
  6. images: [oSprite],
  7. // width, height & registration point of each sprite
  8. frames: {width: oSprite.width / 2, height: oSprite.height, regX: (oSprite.width / 2) / 2, regY: oSprite.height / 2},
  9. animations: {state_true: [1], state_false: [0]}
  10. };
  11. var oSpriteSheet = new createjs.SpriteSheet(oData);
  12. _oTarget = createSprite(oSpriteSheet, "state_" + false, (oSprite.width / 2) / 2, oSprite.height / 2, oSprite.width / 2, oSprite.height);
  13. _oTarget.x = iXPos;
  14. _oTarget.y = iYPos;
  15. _oTarget.stop();
  16. _oParentContainer.addChild(_oTarget);
  17. };
  18. this.unload = function () {
  19. _oParentContainer.removeChild(_oTarget);
  20. };
  21. this.changeState = function (bVal) {
  22. _oTarget.gotoAndStop("state_" + bVal);
  23. };
  24. this.setPosition = function (iXPos, iYPos) {
  25. _oTarget.x = iXPos;
  26. _oTarget.y = iYPos;
  27. };
  28. this.setVisible = function (bVisible) {
  29. _oTarget.visible = bVisible;
  30. };
  31. this._init(iXPos, iYPos, oSprite);
  32. return this;
  33. }