Skip to content

Commit

Permalink
Fix tilemap display problem
Browse files Browse the repository at this point in the history
The renderer could not properly display tiles that are flipped and rotated.
[urho3d#2517](urho3d#2517)
  • Loading branch information
Y-way committed Oct 16, 2019
1 parent 2fdbc1a commit de6a0f1
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Source/Urho3D/Urho2D/StaticSprite2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,36 @@ void StaticSprite2D::UpdateSourceBatches()
vertex2.position_ = worldTransform * Vector3(drawRect_.max_.x_, drawRect_.max_.y_, 0.0f);
vertex3.position_ = worldTransform * Vector3(drawRect_.max_.x_, drawRect_.min_.y_, 0.0f);

vertex0.uv_ = textureRect_.min_;
(swapXY_ ? vertex3.uv_ : vertex1.uv_) = Vector2(textureRect_.min_.x_, textureRect_.max_.y_);
vertex2.uv_ = textureRect_.max_;
(swapXY_ ? vertex1.uv_ : vertex3.uv_) = Vector2(textureRect_.max_.x_, textureRect_.min_.y_);
Rect rect(textureRect_);

if (flipX_)
Swap(rect.min_.x_, rect.max_.x_);

if (flipY_)
Swap(rect.min_.y_, rect.max_.y_);

vertex0.uv_ = rect.min_;
(swapXY_ ? vertex3.uv_ : vertex1.uv_) = Vector2(rect.min_.x_, rect.max_.y_);
vertex2.uv_ = rect.max_;
(swapXY_ ? vertex1.uv_ : vertex3.uv_) = Vector2(rect.max_.x_, rect.min_.y_);

if (swapXY_)
{
Swap(vertex0.uv_, vertex2.uv_);
Swap(vertex1.uv_, vertex3.uv_);
}

if (flipX_)
{
Swap(vertex0.uv_, vertex3.uv_);
Swap(vertex1.uv_, vertex2.uv_);
}

if (flipY_)
{
Swap(vertex0.uv_, vertex1.uv_);
Swap(vertex3.uv_, vertex2.uv_);
}

vertex0.color_ = vertex1.color_ = vertex2.color_ = vertex3.color_ = color_.ToUInt();

Expand Down

0 comments on commit de6a0f1

Please sign in to comment.