// Sprite.js
import BaseElement from './BaseElement.js';

class Sprite extends BaseElement {
  constructor(img, x, y, width, height, engineId) {
    super('div', engineId);
    this.imgElement = document.createElement('img');
    if (img && img.src) {
      this.imgElement.src = img.src;
    } else {
      // 创建一个默认的蓝色圆形作为sprite
      this.imgElement.style.backgroundColor = 'blue';
      this.imgElement.style.borderRadius = '50%';
      this.imgElement.style.width = '100%';
      this.imgElement.style.height = '100%';
    }
    this.imgElement.style.cssText = '-webkit-user-drag: none; user-drag: none;';
    this.element.appendChild(this.imgElement);

    this.setPosition(x, y);
    this.setSize(width, height);
    this.element.setAttribute('data-sprite-id', engineId);
    // 确保sprite可见
    this.element.style.zIndex = '100';
    this.element.style.overflow = 'hidden';

    // 精灵特有方法
    this.name = name => this.element.setAttribute('data-name', name);
    this.animate = keyframes => (this.element.style.animation = keyframes);
  }
}

export default Sprite;
export { Sprite };