GETSPRITESIZE img, width%%, height%%, animframes%%

Previous topic - Next topic

spacefractal

as above tell, this is very much needed, because its so annoying when there is no commands to tell how many frames there is in a animation, so you need to do various workaround (why?).

by now its simply just return the whole image size, but actuelly its should have returned the framesize, which its dosent do that. Howover this is property by design, not a bug.

animframes%% should of course only been optimal, not required. IF that is not possible, then GETANIMFRAMES img, animframes%% could been used as a new command.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

kanonet

Thee is no animated sprite file format. Actually it is just a single, normal, big sprite that contains all frames. When you kload it with LOADANIM you tell him the wide and high of each frame. So if you get the total size of the sprite you know how many frames it contains.

The number of frames should be easy to calculate, must be something like this if im not totally wring:
framenumber = spritehight/tilehigh*spritewidth/tilewith
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

spacefractal

I know and do that, but it's should still tracked by glbasic own. So hence it's a little request, not a bug  :)
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

kanonet

Hmm i dont think we need a command for something that can be done with 2 lines of glb code. But lets see what Gernot says to this.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

fuzzy70

Personally I cannot see the point of such of a command. On the very rare occasion that I do use LOADANIM I know exactly how many frames there are otherwise I wouldn't have created that amount of frames.

The way I deal with all my sprites is with types anyway which holds frames/width/height/filename/handle etc which makes things easier to manage.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

MrTAToad

The easiest way to calculate the number of animations is to load the graphic normally (LOADSPRITE), get the width and height from that an then convert to a sprite sheet with SETSPRITEANIM, and then calculate (width/cell width)*(height/cell height)

spacefractal

The reason is im use a PaintImage() with extra arguments rather than uses draw sprite directly for easier position of that image as well scaling and rotation (I'm not using offbuffer for scaling).

That why its would been nice to calculate frames as well directly without requiring a array or such under loading.

Cold been a new little command or function as well. Howover it's ony idea and low priority completely...
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

#7
etc um using this code (a none rotate support throught here):
Code (glbasic) Select

FUNCTION PaintImage: Name$, x#, y#, alpha#, zoom#, xspot, yspot, special=0

LOCAL h#, w#, img, hh#, ww#, xx#, yy#, SH, SW, i#, r#
IF Name$=0
img=GetStr$(Name$, "Sprites") // Just a name based sprite FUNCTION rather than number. NOT need FOR test here at all.
ELSE
img=Name$
ENDIF
GETSPRITESIZE img, w, h
IF special<0
LOCAL animw=GetStr$(Name$+".w", "Anim"); animw=w/animw
LOCAL animh=GetStr$(Name$+".h", "Anim"); animh=h/animh
w=w/animw
h=h/animh
ENDIF

// some alpha code in that way I prefer. Not a issue in the real alphamode, its just me :-D
SetAlphaMode(alpha#)

// math placement for hotspots
IF xspot=-1 THEN PX=x#
IF xspot=0 THEN PX=ScreenWidth/2.0-(w#*zoom#/2.0)+x#
IF xspot=1 THEN PX=ScreenWidth-w#*zoom#-x#
IF yspot=-1 THEN PY=y#
IF yspot=0 THEN PY=ScreenHeight/2.0-(h*zoom#/2.0)+y#
IF yspot=1 THEN PY=ScreenHeight-h#*zoom#-y#

PW=w*zoom#
PH=h*zoom#
IF PY-PH>ScreenHeight OR PX-PW>ScreenWidth OR PY<-PH OR PX<-PW THEN RETURN

IF alpha#=0 THEN RETURN

IF special<0
LOCAL www=(PX#-((1-zoom#)*w#)/2)
IF PX#-((1-zoom#)*w#)/2>-PW#
STRETCHANIM img, INTEGER(-special)-1, PX#-((1-zoom#)*w#)/2, PY#-((1-zoom#)*h#)/2, PW#, PH#
ENDIF
ELSEIF special=0 OR special=1
ZOOMSPRITE img, PX#-((1-zoom#)*w#)/2, PY#-((1-zoom#)*h#)/2, PW#/w#, PH#/h#
ELSEIF special=2
ZOOMSPRITE img, PX#-((1-zoom#)*w#)/2, PY#-((1-zoom#)*h#)/2, -PW#/w#, PH#/h#
ENDIF
ENDFUNCTION


Its works nice (few array based functions missing here, but you got the idea what its happens), the function (which should of course massure both height and width, not just frames). Alternative the command could been GETANIMSIZE img, w, h, and then massure the rest.

Fell free to use the code of course, if you want to use that and modify it to your own needs, and its of couse a completly none priotity "issue".
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

Is there a command setanim? I think so. You need some getanim to get the applied anim params then. No big deal.