io - What's the best way of reading a sprite sheet in Java? -
i'm writing basic sprite engine own amusement , better aquainted java's 2d api. making use of large numbers of separate .png files transparent backgrounds represent various sprites , different frames of animation need. 'real world' game development projects seem make use of 'sprite sheets' contain multiple sprites or frames of animation within single file. also, rather making use of native image transparency support, people nominate arbitrary colour not appear in sprite pallette transparent colour. how 1 manage file programatically?
- how know 1 sprite starts , next begins
- how deal transparency
there may other factors i've not thought of here, may add list above think of things or people make suggestions (please in comments).
i use xml files generated simple sprite editor store sprite collection of (optionally animated) poses, in turn collection of frames or cells. frames store per-frame information x , y offset of frame in sheet, cell width , height, , transformation (resize/rotation/hue/etc.). poses store individual frames , animation information (speed, example), , pose name identify them in program (hero.pose = sprite.pose["standing_right"]). sprites serve document root hold several poses, such pose each facing direction.
a less flexible alternative used earlier specify fixed sizes cells , sheets , calculate frame offsets , sizes based on these values (e.g. width 32 pixels, third sprite @ 32 * 2). later started specifying these dimensions in file name (e.g. sprite_name_32x64.png) sprites don't fit fixed cell dimensions. new approach more, simplistic editor fills values me , allows me use sprites templates other sprites.
i use alpha , transparency information stored in png images directly don't need worry storing elsewhere, although other approaches pick fixed value per sprite , store somewhere, use leftmost pixel in pose if know it's empty, use specific palette entry if you're using those, sprite masks, or have you.
Comments
Post a Comment