|
Post by neuroflux on Jun 26, 2014 2:33:18 GMT -8
Please see the code in my response post below!
Hey again chaps, I feel like I'm spending more and more time on this forum - gotta be a good thing eh? Anyway, I'm attempting to animate this image as cells: I've converted it using the Asset Convertor and got the header file. When I animate the image - moving right seems to show all 6 cells (like the image above) and moving left shows 1 cell but doesn't animate. The image is 215x84 with 6 cells, each cell is 38 pixels wide: Full code is here: INO file: pastebin.com/raw.php?i=iQ6KB1D0HEADER file: pastebin.com/raw.php?i=NgV9YkSh
|
|
|
Post by neuroflux on Jun 26, 2014 3:11:05 GMT -8
After messing about quite a bit - I managed to get it to draw one cell at a time using BitmapSize(). Now I think I've not created the bitmaps correctly? I was under the impression that you could run one sprite through the asset convertor and use the result? Here's my updated code: pastebin.com/raw.php?i=dFutFfhkand the asset: pastebin.com/raw.php?i=vz7dER5hor did I mis-understand and you actually need to cut each bitmap cell as a separate image? I'm trying to avoid using the SD Card for the moment... as I've lost my only MicroSD !
|
|
|
Post by neuroflux on Jun 27, 2014 4:23:08 GMT -8
Anyone...? I assume this is an error with the asset convertor?
|
|
|
Post by jamesbowman on Jun 27, 2014 5:58:38 GMT -8
The asset converter command-line version cannot not handle multi-frame animations. To do this, or to do anything fancy actually, you must use the asset converter in Python. Here for example is the asset converter for the walk example on p.40 of the book: import Image import gameduino2 as gd2
class Walk(gd2.prep.AssetBin):
def addall(self): walk = gd2.prep.split(32, 32, Image.open("../assets/walk.png"))[1:] self.load_handle("WALK", walk, gd2.ARGB1555)
if __name__ == '__main__': Walk().make()
There are a couple of things the code is doing here. First it uses gd2.prep.split(), which splits an image into a list of subimages. Here each image is 32x32. The second is that the code removes the first image from the list -- because if you look at the sprite sheet the first frame is a standing frame and not part of the walk cycle. OK, so changing this code for your sprite sheet, we need to know how big each sprite is. There are 6 animation frames, but the sheet is 215 pixels wide, which is not an exact multiple of 6. So in an editing program (gimp, Photoshop, etc) you might want to check each frame's alignment in a 36-pixel wide box, and make the image width 216 pixels. Then this code extracts the 6 frames: import Image import gameduino2 as gd2
class Walk(gd2.prep.AssetBin):
def addall(self): walk = gd2.prep.split(36, 84, Image.open("walks.png")) self.load_handle("WALK", walk, gd2.ARGB1555)
if __name__ == '__main__': Walk().make() Running this (e.g. "python mywalk.py") will produce a 6-cell bitmap, and just like on p.40 of the book you can now use the 'cell' to control the animation frame.
|
|
|
Post by neuroflux on Jun 27, 2014 6:57:49 GMT -8
The asset converter command-line version cannot not handle multi-frame animations. To do this, or to do anything fancy actually, you must use the asset converter in Python. Here for example is the asset converter for the walk example on p.40 of the book: import Image import gameduino2 as gd2
class Walk(gd2.prep.AssetBin):
def addall(self): walk = gd2.prep.split(32, 32, Image.open("../assets/walk.png"))[1:] self.load_handle("WALK", walk, gd2.ARGB1555)
if __name__ == '__main__': Walk().make()
There are a couple of things the code is doing here. First it uses gd2.prep.split(), which splits an image into a list of subimages. Here each image is 32x32. The second is that the code removes the first image from the list -- because if you look at the sprite sheet the first frame is a standing frame and not part of the walk cycle. OK, so changing this code for your sprite sheet, we need to know how big each sprite is. There are 6 animation frames, but the sheet is 215 pixels wide, which is not an exact multiple of 6. So in an editing program (gimp, Photoshop, etc) you might want to check each frame's alignment in a 36-pixel wide box, and make the image width 216 pixels. Then this code extracts the 6 frames: import Image import gameduino2 as gd2
class Walk(gd2.prep.AssetBin):
def addall(self): walk = gd2.prep.split(36, 84, Image.open("walks.png")) self.load_handle("WALK", walk, gd2.ARGB1555)
if __name__ == '__main__': Walk().make() Running this (e.g. "python mywalk.py") will produce a 6-cell bitmap, and just like on p.40 of the book you can now use the 'cell' to control the animation frame. Thanks - that explains why I couldn't get it to work!
|
|
|
Post by AlexP on Feb 15, 2016 2:22:35 GMT -8
For using multicell bitmaps i build them first as a vertical strip with the "montage" - Tool from the Imagemagick collection. i.e. if i want to have a sequence of 4 bitmaps (seq0.png, seq.1.png, seq2.png, seq3.png) with the size of 48x48 px. typing on the the commandline: montage -background none -tile 1x4 -geometry 48x48 seq0.png seq.1.png seq2.png seq3.png mysequence.png produce the combined output file mysequence.png with the dimensions of 48px width and 192 px height.
proceeding this file (together with other ones) with the asset converter has als result the header file and amongst other things the bitmap Handler MYSEQUENCE_HANDLE. In my setup part of Arduino code i have to redefine the bitmapLayout with the commands
setup(){ GD.begin(); LOAD_ASSETS(); ... GD.BitmapHandle(MYSEQUENCE_HANDLE); //set the Pointer GD.BitmapLayout(ARGB4,2*48,48); // redefinition of Layout ... }
where
ARGB4 is the Fileformat produced by the asset converter 2x48 is the stride of my Bitmap sequence (the ARGB4 Format has 2 Byte per pixel, an my Bitmap has a width of 48 px) 48 is the height of one bitmal cell in px.
|
|
|
Post by neuroflux on Feb 15, 2016 2:26:37 GMT -8
For using multicell bitmaps i build them first as a vertical strip with the "montage" - Tool from the Imagemagick collection. i.e. if i want to have a sequence of 4 bitmaps (seq0.png, seq.1.png, seq2.png, seq3.png) with the size of 48x48 px. typing on the the commandline: montage -background none -tile 1x4 -geometry 48x48 seq0.png seq.1.png seq2.png seq3.png mysequence.png produce the combined output file mysequence.png with the dimensions of 48px width and 192 px height. processing this file (together with other ones) with the asset converter has als result the header file and among other things the bitmap Handler MYSEQUENCE_HANDLE. In my setup part of Arduino code i have to redefine the bitmapLayout with the commands setup(){ GD.begin(); LOAD_ASSETS(); ... GD.BitmapHandle(MYSEQUENCE_HANDLE); //set the Pointer GD.BitmapLayout(ARGB4,2*48,48); // redefinition of Layout ... }
where: - ARGB4 is the Fileformat produced by the asset converter
- 2x48 is the stride of my Bitmap sequence (the ARGB4 Format has 2 Byte per pixel, an my Bitmap has a width of 48 px)
- 48 is the height of one bitmap cell in px.
Thanks for the response AlexP - However, my Gameduino2 is broken completely so I can no longer develop
|
|