• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

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

ddabrahim

Active member
Tutorial Author
Joined
May 3, 2020
Messages
289
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:

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:
It seems we have this problem only with the default font. If I use a custom font, it solves the problem.
 
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.
 
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:
Nice. Do you still gain something from using drawing lists when you continuously change them every frame?
 
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.
 
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?
 
Back
Top Bottom