User Tools

Site Tools


en:guides:beginners:objects

Part 6 – Objects

Sprites in Orx are called Objects. These are the heart of games in Orx.

Our platform game is going to need a hero. Let's replace the default object in our game with a hero object.

We will need a graphic image for the hero. There's one available over in the Orx project in object assets folder: orx/tutorial/data/object. Look for soldier.png:

Copy this file into your MyGame/data/texture folder.

Next, we need to create a graphic in the config that knows about the soldier.png image:

[HeroGraphic]
Texture        = soldier.png

Next, let's create an actual object that will use the HeroGraphic:

[HeroObject]
Graphic  = HeroGraphic
Position = (-350, 100, 0)
Scale    = 2

When a HeroObject is created in code, he will be placed at co-ordinates -350, 100 on the screen (from the center) and scaled up 2x in size.

In the Init() function, replace the default object with ours:

orxObject_CreateFromConfig("HeroObject");

Compile and run. You should get the following:

So that's great! Now you might be wondering, how does HeroGraphic know how to get solder.png from the data/texture folder? The answer is in the [Resource] section:

[Resource]
Texture = ../data/texture

We can specify multiple paths here and we will do so further down the track.

So good job! Next step is to animate our soldier.


Next: Part 7 – Spritesheets and Animation.

en/guides/beginners/objects.txt · Last modified: 2018/06/27 08:15 (6 years ago) by 127.0.0.1