• 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

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
its about time i started converting all my mojo1 libs to mojo2 and I cant get my head round 1 thing.
in mojo 1 we can load image frames from a sprite sheet. This sprite sheet could have 32 images on (8 rows of 4 columns)

In, mojo2, it looks like all images have to be 1 row when using LoadFrames. Obv this could mean that image width limits can be reached very quickly if everything is on 1 row.
The other way would be to load 4 columns of images in and then uses DrawRect to draw a subset of that imahe (ie 8 rows).
Or do I just load one image in and then use DrawRect to select the image I want?

Or am i missing something really obvious?

Rich
 
Add this to mojo2/graphics.cxs inside the Image class. I have had uploaded this piece to GitHub already but forgot to document it:

Cerberus:
    Function LoadFrames:Image[]( path:String,cellWidth:Int,cellHeight:Int,padded:Bool=False,xhandle:Float=.5,yhandle:Float=.5,flags:Int=Image.Filter|Image.Mipmap,shader:Shader=Null )
        flags&=_flagsMask
    
        Local material:=.Material.Load( path,flags|Texture.ClampST,shader )
        If Not material
            DebugLog ("Error - Unable to load image frames: " + path)
            Return []
        Endif
        
        'Local cellWidth:=material.Width/numFrames,cellHeight:=material.Height
        
        Local x:=0,width:=cellWidth
        If padded x+=1;width-=2
        
        Local tx:Int = material.Width/cellWidth
        Local ty:Int = material.Height/cellHeight
        Local frames := New Image[tx*ty]
        Local i:Int = 0
        For Local yi:Int = 0 To ty-1
            For Local xi:Int = 0 To tx-1
                frames[i]=New Image( material,xi*cellWidth+x,yi*cellHeight,width,cellHeight,xhandle,yhandle )
                i += 1
            Next
        Next
        
        Return frames
    End
 
thank you
Ive been hiding from mojo2 for far too long
 
starter for 10....
Converted my display, button and text class to mojo2
538

SetColor(float,float,float) caught me out to begin with. All my colours were strange as I was still using SetColor(int,int,int)
 
Yup. I don't know why that was changed.

What is your text class doing?
 
I assume float are now used due to shaders being 0-1 for argb values.

My ImageFont class was written a good 10years ago during early days of Monkey. I never really liked the built in font class as I couldn't quickly use bitmap fonts already available.
Code:
Text = New ImageFont("font.png","ABCDEFGHIJKLMNOPQRSTUVWXYX0123456789",32,32)
Text.Draw canvas,"HELLO WORLD",x,y,centerX,centerY

' for multi colour letters
Text.Draw canvas,"HELLO WORLD",x,y,centerX,centerY,multiColorSeed
Or it has the flexibility to only use small subset of the alphabet or other chars
Code:
Text = New ImageFont("font.png","ABCabc+#=",32,64)
My button class then uses the above class for it's font
Code:
Bttn = new button(["HELLO WORLD","CERBERUS X"],X,y,text)


Bttn.Draw(canvas)

Bttn.update()
If bttn.highlighted
  ' someone is touching button
End
If bttn.seleted
  ' someone clicked button
  If btn.option  = 0
    ' clicked on hello world
  End
End
Obviously there now may be better ways to do it in Mojo2
 
Last edited:
Bitmap fonts are now better supported. See the example that ships with CX.
 
Bitmap fonts are now better supported. See the example that ships with CX.
I like that... I like both. Think I'll stick to mine at the mo, but I do like the flexibility of non uniform widths in SetFont
 
On this topic: is the text file that describes variable width bitmap fonts such as in the mojo2 example some sort of standardized format?

Helps says:
Loads a bitmap font file created in tools like GlyphDesigner and alike.
path represents the filename of the texfile that defines the font and its individual glyphs.
( @Holzchopf - typo, missing 't' in 'texfile' :D )

I don't know/can't find what GlyphDesigner is - maybe it's no longer available? Is there some (cross-platform or web-based) equivalent?
 
On this topic: is the text file that describes variable width bitmap fonts such as in the mojo2 example some sort of standardized format?
Yes EZGUI file format. In mid term, CX will have its own tool to create bitmap fonts.
 
Looks perfect, will have a dabble later. Thanks!
 
For some reason, a few of the fonts I tried failed to upload but most worked and the generated fonts work without issue in Cerberus X - great!!

It would be nice to find a similar tool that didn't use Flash.
 
Same here. Is there any good primer on what's different?
So far...
1) All my previous GFXs libraries (eg, particles, buttons etc) all draw to the "back buffer" in Mojo1. They all need changing so that they draw to a canvas instead. Not a bad thing as I can now draw objects like buttons to other canvas before drawing to the screen
2) All mojo1 libraries have RGB colours 0<255. Now they are 0<1 floats (you get very strange results if assigning 0<255 values)
3) A lot more blend modes when drawing
4) Renderers bring lighting and shadows, which can really bring a game to life.
 
Just be aware that mojo2 isn't as fast with high counts of sprites as mojo1 is.
 
Back
Top Bottom