Adam's Lair Forum

game development and casual madness
It is currently 2017/03/26, 11:22

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Canvas & On Screen Text
PostPosted: 2017/02/05, 13:10 
Novice Member
Novice Member

Joined: 2017/02/05, 13:06
Posts: 12
Role: Hobbyist
I'm just getting started with Duality and I'm trying to figure out how to simply draw text on the screen at fixed locations.
I have spent some time searching the forum and I have come to learn that it's done through the "Canvas" object but I haven't been able to find how to get a reference to that object.

Can someone explain this to me, or point me at an existing post where it is explained?


Top
 Profile  
 
PostPosted: 2017/02/05, 13:27 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1933
Location: Germany
Role: Professional
Hey there and welcome!

You're definitely on the right track with the Canvas object, that's the easiest way to quickly just draw some things on screen. The key is that you don't get a reference from somewhere, but you create one yourself when implementing a custom renderer Component: A renderer allows you to draw stuff using an IDrawDevice, and a Canvas is simply a high-level wrapper around that to make it easier.

For now, I'd recommend reading the wiki article on custom renderers. It explains most of this in detail. At the end there is some sample code that might do exactly what you want.

Sometimes it can also be worth it to check out some sample projects, which you can find in the package manager. When you install them they bring their source code along for you to modify and learn from. In this case, the wiki article is more on point, but it doesn't hurt to know that those samples do exist :)

Alright, hope this helps. See you around! ^^

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/02/05, 13:57 
Novice Member
Novice Member

Joined: 2017/02/05, 13:06
Posts: 12
Role: Hobbyist
Very helpful, thank you ! :)


Top
 Profile  
 
PostPosted: 2017/02/05, 14:26 
Novice Member
Novice Member

Joined: 2017/02/05, 13:06
Posts: 12
Role: Hobbyist
One strange thing I'm experiencing is that I'm trying to place my text at 0,0 (top/left corner) and it's appearing there but also at the player's initial position (on world coordinates)
Both get updated.
I think it might be that I attached the component to the player in the duality editor. I'm looking through the examples on GitHub to try to see how I should bring in this component as it seems that it shouldn't be attached to the player but I'm not sure how I'm supposed to open up the sample DualStickSpaceShooter in the duality editor. I can open it in VS of course, but I'd like to see the project in the duality editor to see how the scene is laid out.


Top
 Profile  
 
PostPosted: 2017/02/05, 14:52 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1933
Location: Germany
Role: Professional
When you install the sample using the package manager, there should be a new folder in your Project View called "DualStickSpaceShooter". It contains all the content of the game, including the main scene.

That said, the problem you're experiencing is the signature issue of an IsVisible implementation that returns true a bit too often, specifically: Of a renderer that tells the engine it will be visible both in world space and in screen space.

This is the crucial excerpt from the wiki article:

Code:
    bool ICmpRenderer.IsVisible(IDrawDevice device)
    {
        // Only render when in screen overlay mode and the visibility mask is non-empty.
        return
            (device.VisibilityMask & VisibilityFlag.AllGroups) != VisibilityFlag.None &&
            (device.VisibilityMask & VisibilityFlag.ScreenOverlay) != VisibilityFlag.None;
    }


Check if you have something like this in your code, that should do the trick.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/02/05, 15:05 
Novice Member
Novice Member

Joined: 2017/02/05, 13:06
Posts: 12
Role: Hobbyist
Thanks :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group