ResourceRef Sprite2D::SaveToResourceRef(Sprite2D* sprite) { SpriteSheet2D* spriteSheet = 0; if (sprite) spriteSheet = sprite->GetSpriteSheet(); if (!spriteSheet) return GetResourceRef(sprite, Sprite2D::GetTypeStatic()); // Combine sprite sheet name and sprite name as resource name. return ResourceRef(spriteSheet->GetType(), spriteSheet->GetName() + "@" + sprite->GetName()); }
ResourceRef Drawable2D::GetSpriteAttr() const { SpriteSheet2D* spriteSheet = 0; if (sprite_) spriteSheet = sprite_->GetSpriteSheet(); if (!spriteSheet) return GetResourceRef(sprite_, Sprite2D::GetTypeStatic()); // Combine sprite sheet name and sprite name as resource name. return ResourceRef(spriteSheet->GetType(), spriteSheet->GetName() + "@" + sprite_->GetName()); }
bool Animation2D::Save(Serializer& dest) const { XMLFile xmlFile(context_); XMLElement rootElem = xmlFile.CreateRoot("Animation"); float endTime = 0.0f; for (unsigned i = 0; i < frameSprites_.Size(); ++i) { XMLElement frameElem = rootElem.CreateChild("Frame"); frameElem.SetFloat("duration", frameEndTimes_[i] - endTime); endTime = frameEndTimes_[i]; Sprite2D* sprite = frameSprites_[i]; SpriteSheet2D* spriteSheet = sprite->GetSpriteSheet(); if (!spriteSheet) frameElem.SetString("sprite", sprite->GetName()); else frameElem.SetString("sprite", spriteSheet->GetName() + "@" + sprite->GetName()); } return xmlFile.Save(dest); }