Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Sprite Sheets with uneven number of frames per line

Author
Message
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 8th Aug 2008 03:49
Hey,
i have some sprite sheets that use a diffrent number and size of frames on every line. i have tried chopping up the image to make an even number of sprite frames per line but the closest i have reached the character bobs around constantly as i dind't get the centering quite right

any thoughts ?

YES i did search and couldn't find this specific problem
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Aug 2008 09:57
If I were you, I'd make a smart cutter that can cut out an area based on a starting pixel. So rather than specifying a square section of image, you'd specify the X and Y position of a pixel on the section you want.

The smart cutter itself would simply expand a selection until the border of the selection has no image data. Something along these lines:

Function Smartcutter(img,x,y)

xa=x : ya=y
xb=x : yb=y
done=0
while done=0
pixels=0
nxa=xa
nxb=xb
nya=ya
nyb=yb
for yy=ya to yb
for xx=xa to xb
if xx=xa or xx=xb or yy=ya or yy=yb
pixcol=point(xx,yy)
if pixcol>0
inc pixels,1
if xx=xa then nxa=xa-1
if xx=xb then nxb=xb-1
if yy=ya then nya=ya-1
if yy=yb then nyb=yb+1
endif
endif
next xx
next yy
xa=nxa
xb=nxb
ya=nya
yb=nyb
if pixels=0 then done=1
wend

if image exist(img)=1 then delete image img
get image img,xa+1,ya+1,xb-0,yb-0,1

Endfunction


This function is not tested, but it's supposed to start of at a spawn pixel and expands a selection box until the edges have no pixels, each time if finds a pixel it will check to see which side it's on, then adjust the selection range to suit - so if there's a pixel along the top border, the YA variable is decreased.

You would have to ensure that each sprite had a border of at least 1 pixel, so space them out a bit otherwise this function could try and check ranges outside the screen - but the principal at least would let you avoid annoying image grabbing.

One thing that'll surely be an issue is the hot spot - with images it's usually best to make an array to store some parameters, like the hot spot location, image size, whatever you need. You could even keep a record of the areas the function finds, then save this data to prevent from having to check the image every time. Personally I'd use that location that you pass to the function as the hot spot, fairly easy to add that feature to the function. Another thing though is that if you did this, the hot spot would need to definately be a pixel and not background, otherwise it would only capture that pixel.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-05-04 20:02:02
Your offset time is: 2024-05-04 20:02:02