import { EntityProperties } from "../entity/entityProperties"; import { Rotation } from "../../../type/entity/RotationStyle"; import { Sprite } from "../sprite"; import { SpriteCostume } from "./spriteCostume"; import type { ISprite } from "../../../type/entity/sprite"; import type { ScratchRenderProperties } from "../../../type/render/IRenderWebGL"; /** * SpriteProperties */ export class SpriteProperties extends EntityProperties { constructor(sprite: ISprite){ super(sprite); } update() { const entity = this.entity as ISprite; let _degree = this.degree; let _scale = {w: this.scale.w, h: this.scale.h}; if( this._rotation == Rotation.DONT_ROTATE) { _degree = 90; }else if( this._rotation == Rotation.LEFT_RIGHT) { if( _degree < 0 || _degree > 180 ) { _degree = 90; _scale.w = - Math.abs( _scale.w ); }else{ _degree = 90; _scale.w = Math.abs( _scale.w ); } } const _sprite = this.entity as Sprite; const _drawable = _sprite.render.renderer._allDrawables[_sprite.drawableID]; if(_drawable && _drawable.skin ) { // _drawable.skinに対してメソッドを発行する。Skinが出来上がっていないうちは回避する const fencedPosition = _sprite.render.renderer.getFencedPositionOfDrawable(_sprite.drawableID, [this.position.x, this.position.y]); this.position.x = fencedPosition[0]; this.position.y = fencedPosition[1]; } const prop: ScratchRenderProperties = { skinId: (entity.Costume as SpriteCostume).currentSkinId, position: [this.position.x, this.position.y], scale: [_scale.w, _scale.h], direction: _degree, visible: this.visible, }; this.updateDrawableProperties(prop); } }