levelPackIcon.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function LevelPackIcon(icon, text) {
  2. LevelPackIcon.superclass.constructor.apply(this, [icon.width, icon.height]);
  3. this.icon = icon;
  4. this.label = new TrinText(text);
  5. this.label.setStyle("font", this.fontBaseSize, true, "#FFFFFF");
  6. this.orign.x = this.icon.width / 2;
  7. this.orign.y = this.icon.height / 2;
  8. this.add(this.icon);
  9. this.add(this.label);
  10. this.isButton = this.icon instanceof TrinButton;
  11. }
  12. extend(LevelPackIcon, TrinGroup);
  13. LevelPackIcon.prototype.update = function() {
  14. LevelPackIcon.superclass.update.apply(this);
  15. if (this.isButton) {
  16. if (this.bounds.intersects(_TrinGame.mouse.x, _TrinGame.mouse.y)) {
  17. this.icon.currentFrame = 1;
  18. if (_TrinGame.mouse.isReleased()) {
  19. if (this.icon.currentAnimation.frames.length > 2) {
  20. this.icon.currentFrame = 2;
  21. } else {
  22. this.icon.currentFrame = 0;
  23. }
  24. if (!this.icon.opensLink && this.icon.onClick !== undefined && this.icon.onClick !== null) {
  25. this.icon.onClick();
  26. }
  27. }
  28. } else {
  29. this.icon.currentFrame = 0;
  30. }
  31. if (this.icon.isHovered()) {
  32. this.label.y = 200 * this.icon.scale.y;
  33. this.label.x = 105 * this.icon.scale.x;
  34. this.label.setStyle("font", this.fontHoverSize, true);
  35. } else {
  36. this.label.y = 190 * this.icon.scale.y;
  37. this.label.x = 110 * this.icon.scale.x;
  38. this.label.setStyle("font", this.fontBaseSize, true);
  39. }
  40. }
  41. };
  42. LevelPackIcon.prototype.minIconScale = 0.6;
  43. LevelPackIcon.prototype.fontBaseSize = 48;
  44. LevelPackIcon.prototype.fontHoverSize = 56;