How to load images with frames? mojo2 woes...

Monkey Forums/Monkey Programming/How to load images with frames? mojo2 woes...

RedGTurtlepa(Posted 2016) [#1]
I got mojo2 recently, and I was tyring to use it, as I thought it would make life better. But now I am getting a ton of issues.


I'm trying to store the image frames as a global img:Image[], but for some reason the image renders as a black. This doesnt make sense. I also dont like how the code renders images into some Material, to find its overall cell width and height.

so Im trying this
global img:Image[] = []

function OnCreate:Int()
//create canvas
img = Image.LoadFrames("img.png", framesCount, False)
end

On Draw, and nothing but a black box.

Doesnt .LoadFrames return an array of images? Or no. Does it instead return an Image object that contains a frame array of images?
I'm getting more issues using Monkey/mojo2 than I think I can handle.
Anyway, this isnt in the documents, but does rendering 32 bit depth images have issues when using this command? I dont understand.


Amon(Posted 2016) [#2]
Strict
Import mojo

Function Main:Int()
	New Game()
	Return 0
End

Class Game Extends App
    Field myImage:Image
    ' declare a field to hold your image.
	
	Method OnCreate:Int()	
		
		SetUpdateRate(60)
		myImage = LoadImage("path/to/image/myImage.png", 64, 64, 8, Image.DefaultFlags)
		'The above then Loads the image into myImage using LoadImage. 
        'The first parameter of LoadImage needs the location of tyhe image. 
        'the 2nd and 3rd parameters ask for the wqidth and height of each cell within the image
        'The fourth parameter asks how frames witrhin the image. the 3rd assigns to the image the blend/attribute flags
        
        ' so we have an image which has 8 frames, 64px by 64px. 64 * 8 = 512. As an example then, the image would be 512 pixels wide and 64 pixels in height.
        
		Return 0
	End
	
	
	Method OnUpdate:Int()
        DrawImage(myImage, 50, 100, 2)
        'We draw the image, at x location 50px and at y location 100px and display frame 2 of the image
		Return 0
	End
	
	
	Method OnRender:Int()
		Cls()
		
		Return 0
	End
End



This is how its done in mojo1. Surely there is something similar in mojo2. Apologies for not checking.


Goodlookinguy(Posted 2016) [#3]
I wrote some static functions that can be used for loading frames in mojo2, take a look and see if that's more of what you were looking for - https://bitbucket.org/Goodlookinguy/xaddon/src/67a01fdb491b13c1d29884949c95ef6c7937c02b/moxy/moxyimage.monkey?at=default&fileviewer=file-view-default

As for the black image issues, images encoded in weird ways can cause it. Don't know why and don't know what specific encodes cause it.