forked from cirosantilli/Urho3D-cheat
/
sprite_repeat.cpp
50 lines (45 loc) · 1.85 KB
/
sprite_repeat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Expected outcome: two falling boxes on a ground. Box sprites are correctly scaled to match the physical bodies.
- https://stackoverflow.com/questions/47488411/how-to-scale-a-sprite2d-in-urho3d-without-rescaling-the-entire-node
- https://discourse.urho3d.io/t/how-to-scale-a-sprite2d-in-urho3d-without-rescaling-the-entire-node/3785
*/
#include "common.hpp"
using namespace Urho3D;
class Main : public Common {
public:
Main(Context* context) : Common(context) {}
virtual void StartExtra() override {
auto groundWidth = this->GetWindowWidth();
auto groundHeight = this->GetWindowWidth() / 10.0f;
auto width = this->GetWindowWidth() / 2.0f;
auto height = this->GetWindowHeight() / 4.0f;
auto node = this->scene->CreateChild("Box");
node->SetPosition2D(Vector2(this->GetWindowWidth() / 2.0f, this->GetWindowHeight() / 2.0f));
auto box = node->CreateComponent<CollisionBox2D>();
box->SetSize(Vector2(width, height));
auto body = node->CreateComponent<RigidBody2D>();
auto boxSprite = this->resourceCache->GetResource<Sprite2D>("Urho2D/Box.png");
//boxSprite->SetRectangle(IntRect(0, 0, 100, 100));
auto staticSprite = node->CreateComponent<StaticSprite2D>();
staticSprite->SetCustomMaterial(this->resourceCache->GetResource<Material>("Materials/StoneTiled.xml"));
//staticSprite->SetSprite(boxSprite);
//staticSprite->SetDrawRect(Rect(
//width / 2.0f,
//-height / 2.0f,
//-width / 2.0f,
//height / 2.0f
//));
//staticSprite->SetUseDrawRect(true);
//staticSprite->SetTextureRect(Rect(
//width / 2.0f,
//-height / 2.0f,
//-width / 2.0f,
//height / 2.0f
//));
//staticSprite->SetUseTextureRect(true);
}
private:
Node *groundNode;
Sprite2D *boxSprite;
};
URHO3D_DEFINE_APPLICATION_MAIN(Main);