• 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

can't get loadimage to work

meems

New member
Joined
Feb 28, 2018
Messages
3
Code:
Import mojo
Function Main()
Local b:Image=LoadImage("block.png")
End

just trying to get 1st program to acknowledge an image
get surface null error.
I've stuffed the block.png in every directory that I can think cerebus would look for it.
 
Hi.

Code:
Strict

Import mojo

Class myGame Extends App
    Field b:Image

    Method OnCreate:Int()
        SetUpdateRate(0)
        b = LoadImage("block.png")
        Return 0
    End

    Method OnUpdate:Int()
        Return  0
    End

    Method OnRender:Int()
        DrawImage(b, 400, 300)
        Return 0
    End
End

Function Main:Int()
    New myGame
    Return 0
End

Make sure the image is stored inside the yourGameName.data folder.
 
Last edited:
thx. it works now. don't know why my much simpler code didn't work though. I'm guessing images can't be loaded until app is loaded, in the same way images can't be loaded in blitz until graphics is initiated
 
Yes, I'm not certain but it's quite likely that you need to create an app-derived class to get all the mojo infrastructure such as LoadImage working. [Edit: posted at the same time - looks like this was indeed the answer.]

[You can run plain Monkey programs from Main(), e.g. printing out Fibbonaci numbers to the console or something.]
 
When it comes to mojo and mojo2, you need to extend your own class from the App class and work with that.

Using only the Main function, well only of Console apps and some text printing in the HTML target. Or you run your own graphics/input/sound/etc module. OpenGL would go too I guess, but then you are missing input and stuff like that.
 
@meems: Images should be loaded in App.OnCreate() (or later).
The reference page of mojo.app says the following:
The OnCreate method is called when mojo has been initialized and the application has been successfully created.
At this point, applications can start loading resources such as images and sounds, and set the update rate using SetUpdateRate.
The return value of this method is currently ignored, but should be 0 for future compatibility.
 
No need to add to this topic. After his short visit here he announced on Syntaxbomb that he won't use CX. To advanced for him.
 
Mike you are an all seeing eye. But I'm fickle, and its early days in my move to bmax. I'm learning new stuff everyday. Who knows, tomorrow I might become aware of something about bmax or cerebus that convinces me to use cerebus. Take heart that cerebus is #2 on my list after bmax-ng.

now excuse me while I write out a rant on syntax bomb about case sensitive languages!
 
Back
Top Bottom