About Monkey 2 › Forums › Monkey 2 Programming Help › Where is Image.GrabImage ?
This topic contains 3 replies, has 2 voices, and was last updated by
gcmartijn 2 years, 8 months ago.
-
AuthorPosts
-
August 7, 2016 at 12:24 pm #2837
I’m busy with translating code but now i’m searching for this monkey1 function
http://www.monkey-x.com/docs/html/Modules_mojo.graphics_Image.html#GrabImage
Monkey12345678Image = atlas_sprite.GrabImage(frame["x"].ToInt(),frame["y"].ToInt(),frame["w"].ToInt(),frame["h"].ToInt(),1,Image.Handle)My game uses many sprites (and animations) using atlas files.
But I can’t find this function for MX2August 7, 2016 at 12:51 pm #2838You can grab a sub-section of an image with new image(image, recti) plus there’s a few other overloaded options I think. Here’s my function to load an animation from a spritesheet, it might have what you’re looking for?
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142Function LoadFrames:Image[] (path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, padded:Bool = False, flags:TextureFlags = TextureFlags.Filter, shader:Shader = Null)Local material:=Image.Load( path, flags, shader )If Not material Return New Image[0]If cellWidth * cellHeight * numFrames > material.Width * material.Height Return New Image[0]Local frames:= New Image[numFrames]If cellHeight = material.HeightLocal x:=0local width:=cellWidthIf paddedx += 1width -= 2End ifFor Local i:=0 Until numFrameslocal rect:= New Recti(i * cellWidth + x, 0, i * cellWidth + x + width, cellHeight)frames[i] = New Image(material, rect)NextElseLocal x:= 0, width:= cellWidth, y:= 0, height:= cellHeightLocal columns:= material.Width / widthIf paddedx += 1y += 1width -= 2height -= 2End IfFor Local i:=0 Until numFramesLocal fx:Int = i Mod columns * cellWidthLocal fy:Int = i / columns * cellHeightlocal rect:= New Recti(fx + x, fy + y, fx + x + width, fy + y + height)frames[i] = New Image(material, rect)NextEnd IfReturn framesEndAugust 7, 2016 at 1:03 pm #2839Thanks for sharing, I found the image overload in the modules section now.
+1
August 13, 2016 at 2:42 pm #2968I’m wondering if there are some Atlas restrictions like grapimage have.
These are.
Multiple frame images are assumed to be laid out in a horizontal strip, in which case width and height are the dimensions of each frame, and the source image must be wide enough to contain the entire strip.
Note that if image flags includes any padding, then the specified rectangle includes padding. This means image width and/or height may be ‘2 less’ than the width and/or height you specify.For New Image(img,recti(x,y,x2,y2))
Because I get some weird things using a new spritesheet Atlas creator.
I guess that all sort of Atlas image formats are now allowed , and no 1px padding is needed anymore ?
Usefull information for others.
-
AuthorPosts
You must be logged in to reply to this topic.