kiel814 wrote:
Hello everyone, I've only recently downloaded Duality and I'm really struggling with it.
Hello and welcome!

kiel814 wrote:
I've read the introduction, tutorials, basic topics, etc. I also completed the space shooter example.
kiel814 wrote:
Now my game takes place in a building (much like sim tower, if you had the pleasure).
Yes, yes I had

Now that the pleasantries are out of the way, let's get on the juicy bits
kiel814 wrote:
So I want to dinamically create floors and then add rooms to the floors. Needless to say, these rooms are not created at the beginning of the game, but are created by the player as the game progresses.
So I create a GameObject "room" and I add a Transform Component to set it's position on the screen. But I'm stuck adding the SpriteRenderer to it. And how do I set the pixmap which is already loaded in the Project View into the renderer?
Can anyone point me in the right direction? Is even a sprite renderer what I need? I'm only going for it because that is what's created when I create a game object from a pixmap in the editor...
You are right on track:
you need to create a
GameObject, fill it with all the required
Components (
Transform and
SpriteRenderer for example) and then, remember to add it to the
Scene. Something like this, assuming that this code is part of a
Component running inside your
game Scene (this is my style.. don't take it as immutable)
Code:
{
...
TowerRoom room = ...;
this.GameObj.ParentScene.AddObject(CreateNewRoom(room))
}
private GameObject CreateNewRoom(TowerRoom room)
{
GameObject go = new GameObject(room.Name);
go.AddComponent<Transform>();
go.AddComponent<SpriteRenderer>();
go.GetComponent<Transform>().Pos = new Vector3(room.Position, 0);
// actual size depends on your sprite of course
go.GetComponent<SpriteRenderer>().Rect = Rect.Align(Alignment.Center, 0, 0, 256, 256);
// also here you will want to load a different material depending on the room type
go.GetComponent<SpriteRenderer>().SharedMaterial = ContentProvider.RequestContent<Material>(@"Data\Path\To\My\Material.Material.res").Res;
return go;
}
Otherwise, you could explore the wonderful world of
Prefabs (see below about where you can find some info in general)
kiel814 wrote:
I have used Irrlicht in the past, but I wanted to switch to something in C#, game-oriented and 2D specific. But this "your code does not use the engine, the engine uses your code" has me really puzzled.
That's an inspirational quote that basically means that, unlike other game engines where you provide the program's entry point and reference the engine, in this case it's actually the engine that references your classes to play the game

kiel814 wrote:
Also, are there some sample projects where I figure out this basic stuff? Where?
You can check the
tutorial section on the forum (though they might be old, they should still work or require a minimum amount of tinkering to make them work with the newer versions of Duality), the
samples in the Package Manager of Duality itself, and feel free to
join the chat on Discord if you need pseudo-real-time help
