• 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

Mojo2 load image

Ferret3D

New member
Joined
Aug 13, 2017
Messages
88
I cant get an image to load, what am i doing wrong?
I have a game.data folder.

Code:
Import mojo2

Class MyApp Extends App
    Field canvas:Canvas
    Field test:Image
   
    Method OnCreate()
        canvas = New Canvas
        SetUpdateRate 60
       
        test.Load("test.jpg")

    End
   
    Method OnUpdate()
   
    End
   
    Method OnRender()
   
        canvas.Clear 0,0,1
       
        canvas.DrawImage(test)
       
        canvas.Flush
       
    End
End

Function Main()
    New MyApp
End
[\code]
 
Is your script named game.cxs? They both have to be the same before the postfix.

game.cxs
game.data


Also on mobile platforms, the file names are case sensitive. So Test.jpg and test.jpg would be two different images. Make sure your file name inside the script is equal to the actual file name.
 
PhotoPuzzle.cxs
PhotoPuzzle.data
test.jpg

When i try to draw the image,
Cerberus Runtime Error : Null object access
 
Can you please zip the project and attach it here? Will have a look later.
 
I cant get an image to load, what am i doing wrong?
You are basically calling a static class function that returns a Image object as a result and not assigning the result into a 'handle' variable of the data type expected, in this case Image.

Now if I remember when you declare an variable with Field in a class and create this class with New, all Fields are given a default value, unless you over-ride by assigning a value. This default value depends on the data type assigned, e.g. int = 0, float = 0.0, String = "" and Class objects such as Image are given the value of Null. So when you declared test as a field you basically created an empty data object of the Image class with an alias name of test with access to all those static functions ready for use, but it has no data.

Now as the Image class has a static function called Load; this is not a method. You should think of calls defined with Function as static or global to a class, these only operate at class level and not on the objects that you create with the New keyword; that's what you would use methods for.

The correct way is to assign the result as York has shown.
 
Last edited:
This one should be Sticky Topics because you dont want every New Beginner Cerberus Users repeating the same questions when posting new topics on the forum if they get stuck on how to display images on screen!
 
If the docs stayed the way they are, yes of course. But I really hope, we don't need these kind of threads once the new docs are in place.
 
Back
Top Bottom