Mojo2

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
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
 

MikeHart

Administrator
Joined
Jun 19, 2017
Location
Germany
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 X:
    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
 

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
thank you
Ive been hiding from mojo2 for far too long
 

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
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)
 

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
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:

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
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
 

Paul59

Active Member
CX Code Contributor
Joined
Dec 13, 2018
Location
UK
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?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Location
Germany
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.
 

Paul59

Active Member
CX Code Contributor
Joined
Dec 13, 2018
Location
UK
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.
 

Rich

Active Member
3rd Party Module Dev
Joined
Sep 9, 2017
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.
 
Top Bottom