void AnimatedSprite2D::OnFlipChanged() { for (unsigned i = 0; i < numTracks_; ++i) { if (!trackNodes_[i]) continue; StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>(); staticSprite->SetFlip(flipX_, flipY_); } // For editor paused mode UpdateAnimation(0.0f); }
void AnimatedSprite2D::SetFlip(bool flipX, bool flipY) { if (flipX == flipX_ && flipY == flipY_) return; flipX_ = flipX; flipY_ = flipY; for (unsigned i = 0; i < timelineNodes_.Size(); ++i) { if (!timelineNodes_[i]) continue; StaticSprite2D* staticSprite = timelineNodes_[i]->GetComponent<StaticSprite2D>(); staticSprite->SetFlip(flipX_, flipY_); } // For editor paused mode UpdateAnimation(0.0f); MarkNetworkUpdate(); }
void AnimatedSprite2D::SetAnimation(Animation2D* animation, LoopMode2D loopMode) { if (animation == animation_) { SetLoopMode(loopMode_); currentTime_ = 0.0f; UpdateAnimation(0.0f); return; } for (unsigned i = 0; i < numTracks_; ++i) { if (trackNodes_[i]) trackNodes_[i]->SetEnabled(false); } numTracks_ = 0; trackNodes_.Clear(); trackNodeInfos_.Clear(); animation_ = animation; if (!animation_) return; currentTime_ = 0.0f; if (!rootNode_) { rootNode_ = GetNode()->CreateChild("_root_", LOCAL); rootNode_->SetTemporary(true); } numTracks_ = animation_->GetNumTracks(); trackNodes_.Resize(numTracks_); trackNodeInfos_.Resize(numTracks_); for (unsigned i = 0; i < numTracks_; ++i) { const AnimationTrack2D& track = animation->GetTrack(i); SharedPtr<Node> trackNode(rootNode_->GetChild(track.name_)); StaticSprite2D* staticSprite = 0; if (trackNode) { // Enable track node trackNode->SetEnabled(true); // Get StaticSprite2D component if (track.hasSprite_) staticSprite = trackNode->GetComponent<StaticSprite2D>(); } else { // Create new track node trackNode = rootNode_->CreateChild(track.name_, LOCAL); trackNode->SetTemporary(true); // Create StaticSprite2D component if (track.hasSprite_) staticSprite = trackNode->CreateComponent<StaticSprite2D>(); } if (staticSprite) { staticSprite->SetLayer(layer_); staticSprite->SetBlendMode(blendMode_); staticSprite->SetFlip(flipX_, flipY_); staticSprite->SetUseHotSpot(true); } trackNodes_[i] = trackNode; trackNodeInfos_[i].hasSprite = track.hasSprite_; } SetLoopMode(loopMode); UpdateAnimation(0.0f); MarkNetworkUpdate(); }
void AnimatedSprite2D::SetAnimation(Animation2D* animation, LoopMode2D loopMode) { if (animation == animation_) { SetLoopMode(loopMode_); currentTime_ = 0.0f; UpdateAnimation(0.0f); return; } for (unsigned i = 0; i < timelineNodes_.Size(); ++i) { if (timelineNodes_[i]) timelineNodes_[i]->SetEnabled(false); } timelineNodes_.Clear(); animation_ = animation; if (!animation_) return; currentTime_ = 0.0f; if (!rootNode_) { rootNode_ = GetNode()->CreateChild("RootNode", LOCAL); rootNode_->SetTemporary(true); } timelineNodes_.Resize(animation_->GetNumTimelines()); timelineTransformInfos_.Resize(animation_->GetNumTimelines()); for (unsigned i = 0; i < animation_->GetNumTimelines(); ++i) { const Timeline2D& timeline = animation->GetTimeline(i); SharedPtr<Node> timelineNode(rootNode_->GetChild(timeline.name_)); StaticSprite2D* staticSprite = 0; if (timelineNode) { // Enable timeline node timelineNode->SetEnabled(true); // Get StaticSprite2D component if (timeline.type_ == OT_SPRITE) staticSprite = timelineNode->GetComponent<StaticSprite2D>(); } else { // Create new timeline node timelineNode = rootNode_->CreateChild(timeline.name_, LOCAL); // Create StaticSprite2D component if (timeline.type_ == OT_SPRITE) staticSprite = timelineNode->CreateComponent<StaticSprite2D>(); } if (staticSprite) { staticSprite->SetLayer(layer_); staticSprite->SetBlendMode(blendMode_); staticSprite->SetFlip(flipX_, flipY_); staticSprite->SetUseHotSpot(true); } timelineNodes_[i] = timelineNode; timelineTransformInfos_[i].parent_ = timeline.parent_; } SetLoopMode(loopMode); UpdateAnimation(0.0f); MarkNetworkUpdate(); }