Skip to content

HelloWorld Tutorial

zeitt edited this page Sep 4, 2014 · 7 revisions

Adding first object & component for it

Add GameObject* to class declaration of your scene ie.

uth::GameObject* helloGO;

After that simply create initialize GameObject in the Init function:

helloGO = new uth::GameObject();

Add text component for it is also very simple:

helloGO->AddComponent(new Text("kenpixel.ttf", 24.f));

helloGO->GetComponent<Text>("Text")->AddText("Hello World!");

If (and when) you want to see your gameobject on-screen you have to call objects Draw function in Scene's draw.

helloGO->Draw(uthEngine.GetWindow());

Adding animated object

Adding animated sprite is just as easy:

Add gameobject to class declaration ->

create empty object ->

add AnimatedSprite component ->

animGO->AddComponent(new uth::AnimatedSprite(&uthRS.LoadTexture("planetsheet.tga"), 25, 5, 5, 10));

draw object ->

Update object every frame (add go's update to YourScene::Update(float dt))

animGO->Update(dT);

Translating object with mouse

NOTE: Mouse origin is in the center of screen instead of upper-right corner. (This behavior might/should change during development.)

First we should correct origin with camera:

uthEngine.GetWindow().GetCamera().SetPosition(uthEngine.GetWindow().GetSize()/2);

Then we just replace object to new position every frame (YourScene::Update(float dt))

animGO->transform.SetPosition(uthInput.Mouse.Position());

Clone this wiki locally