Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Initializing uneven sized sprites  (Read 1948 times)
0 Members and 1 Guest are viewing this topic.
Offline westloar

Junior Devvie





« Posted 2012-04-20 09:32:45 »

I'm prototyping my game and using a sprite sheet I downloaded, the image loader that I use cuts the image up into equal parts and loads each one.

The problem I have is the walk animation, for instance, contains sprites that are of uneven width:



Aside from measuring and supplying my image loader with specific dimensions for each image, what's the best way to split up the sprites and load it?
Offline gimbal

JGO Knight


Medals: 25



« Reply #1 - Posted 2012-04-20 09:59:24 »

I like dumb code, so I actually don't deal with it. In stead, I do this:

a) I make all frames of an animation equal width and height, which probably means adding plenty of blank space in the slimmer frames. Different animations can have different dimensions though
b) my positioning system does not orient from the top-left or bottom-left corner of a sprite/bob but from the center-bottom 'pixel'. This keeps the thing in the same place no matter that there are differences in animation width; even if you would allow different frame widths. Using the center-bottom also just makes things like floor collision checks slightly easier.

Unfortunately to properly work with a) does require a tiny bit of extra effort; I generate bounding boxes on a per-frame basis by examining the blank space and making the bounding box fit as tight around the opaque area of the frame as possible. But meh, thats the type of code you write once and copy everywhere.
Offline westloar

Junior Devvie





« Reply #2 - Posted 2012-04-20 10:36:44 »

Ok,that was my first thought, I just thought there might be a more elegant solution Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gimbal

JGO Knight


Medals: 25



« Reply #3 - Posted 2012-04-20 10:37:52 »

Ok,that was my first thought, I just thought there might be a more elegant solution Tongue

Perhaps there is, but that reads to me like you are searching for the "best" way of doing it, which doesn't exist. I settle for a solution that is good enough.
Offline westloar

Junior Devvie





« Reply #4 - Posted 2012-04-20 10:54:57 »

tousche' good sir  Grin
Offline ReBirth
« Reply #5 - Posted 2012-04-20 12:58:49 »

I prefer your unchosen method, by measure them manually. With your sprite above, I just need store 7 (or 6) int in an array. Ofc you need to update code as art one but it could be avoided if you already fix at the sprite.

Offline davedes
« Reply #6 - Posted 2012-04-20 17:23:17 »

For uneven sprites I use this little class:
http://www.java-gaming.org/?action=pastebin&id=70

Issues:
  • It means I need to manually find the integer coordinates (i.e. zoomed in using Photoshop)
  • It's better for arbitrary sprites than animations (where your names are going to end up char1, char2, char3, char4, etc).
  • In some cases using uneven sizes will result in a jumpy animation, if the character isn't lined up frame to frame. If this is the case, it would be much easier to just edit the sprites in Photoshop so that they are (a) lined up frame to frame, and (b) evenly spaced.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xFryIx (52 views)
2014-11-13 12:34:49

digdugdiggy (34 views)
2014-11-12 21:11:50

digdugdiggy (29 views)
2014-11-12 21:10:15

digdugdiggy (23 views)
2014-11-12 21:09:33

kovacsa (46 views)
2014-11-07 19:57:14

TehJavaDev (50 views)
2014-11-03 22:04:50

BurntPizza (49 views)
2014-11-03 18:54:52

moogie (65 views)
2014-11-03 06:22:04

CopyableCougar4 (63 views)
2014-11-01 23:36:41

DarkCart (148 views)
2014-11-01 14:51:03
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!