noBug [SOLVED]DrawList.DrawText does not draw value of variable

ddabrahim

Active member
Tutorial Author
Joined
May 3, 2020
Messages
148
Hi.

I'm not too sure if this is a bug but this is what I experience.

I use DrawList.DrawText to draw text on the screen and if I would like to display the value of a variable that is static, it is works fine. However, if I change the value of the variable, it does not draw numbers on the screen but squares instead.

Image:
result.png


What you see on the image is that I increase the value of a variable every frame by 1 when I use Canvas.DrawText to draw this value on the screen, it is works fine, but when I use DrawList.DrawText I get squares drawn on the screen instead of numbers.

The code looks like this with the solution:

code_language.cerberus:
Import mojo2

Class Game Extends App

    Field myCanvas:Canvas
    Field myDrawList:DrawList
    Field myVar:Int

    Method OnCreate()
        myCanvas = New Canvas()
        SetUpdateRate(60)
     
        myVar = 0

        myDrawList = New DrawList()

    End

    Method OnUpdate()
        myVar += 1
    End

    Method OnRender()
        gameCanvas.Clear(0,0,1,1)
     
        myCanvas.DrawText("Canvas.DrawText: " + myVar, 50, 50)

        myDrawList.DrawText("DrawList.DrawText: " + myVar, 50, 100)
        myDrawList.RenderDrawList(myDrawList, 50,100)
        myDrawList.Reset()
     
        gameCanvas.Flush()
    End
 
End


Is this a bug and is there any solution to this?

Thanks.
 
Last edited:

ddabrahim

Active member
Tutorial Author
Joined
May 3, 2020
Messages
148
It seems we have this problem only with the default font. If I use a custom font, it solves the problem.
 

ddabrahim

Active member
Tutorial Author
Joined
May 3, 2020
Messages
148
However, now I have an other problem. it seems the previous render is not get cleared from the screen and DrawList.DrawText is draw over and over the previous.

Image:
customFont.png


Wondering if this is why I'm getting white squares with the default font?

Could anyone please tell me what am I doing wrong?

Thanks.
 

ddabrahim

Active member
Tutorial Author
Joined
May 3, 2020
Messages
148
Okay. It seems, in addition to Canvas.Clear() we also need to call DrawList.Reset() to clear the drawlist. It is solves all problems and now I understand what is the real purpose of DrawList and realised the Canvas is a DrawList and in-fact we have access to all methods of DrawList from the canvas too. I should read the docs more carefully :D

I have updated the above code to reflect this in case someone get this problem too.
 
Last edited:

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
578
Nice. Do you still gain something from using drawing lists when you continuously change them every frame?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,845
I guess that depends highly of what you want to draw and how many you draw. I recomment it after my last tries but for sure you should test it.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
578
guess that depends highly of what you want to draw and how many you draw.

I didn't think of that I'm gonna check that out. Can you draw with a different scale, rotation and alpha and it would still count as the same list?
 
Top Bottom