DrawImage - ImageFragments on SpriteSheets
Monkey Forums/Monkey Programming/DrawImage - ImageFragments on SpriteSheets
| ||
| Hi, When I load a 64x64x8 Image Spritesheet with LoadImage and draw it using DrawImage and use float coordinates, fragments (a pixel or so) from the neighboring frames in this spritesheet occuring. I've made a short example to reproduce the bug:
Import mojo
Class MyApp Extends App
Field i:Image
Field f:Float = 0
Field x:Float = 200
Field y:Float = 200
Field fr:Int
Method OnCreate:Int()
Print "Create"
i = LoadImage("ship_1.png", 64, 64, 8)
SetUpdateRate(60)
End
Method OnUpdate:Int()
f += 0.02
fr += 1
If f >= 8 Then f -= 8
x += Sin(fr)
y += Cos(fr)
End
Method OnRender:Int()
Cls(0,0,255)
DrawText "test",0,0
DrawImage i, x, y, f
End
End
Function Main:Int()
New MyApp
End
Download my example sprite sheet from here: ship_1.png With a cast to Int everthing is fine: DrawImage i, Int(x), Int(y), f |
| ||
Have you tried the padding flags when you load the image?Function LoadImage:Image( path$, frameWidth, frameHeight, frameCount, flags=Image.DefaultFlags ) DefaultFlags: The image flags used by default when an image is loaded or created. Image flags can be one of: Image.MidHandle - indicates the image should be automatically handled by its centre once reated. Image.XPadding - indicates each image frame includes a one pixel padding border to the left and to the right. Image.YPadding - indicates each image frame includes a one pixel padding border above and below. Image.XYPadding - indicates both XPadding and YPadding. See also: LoadImage, GrabImage |
| ||
| OpenGL will calculate your pixels using float values, and it may be a little different than expected, usually +- 1 pixel. This is something that happens across the board. Pad the images and should work with float values. |
| ||
| thanks for explanation! |