GLBasic forum

Feature request => 2D => Topic started by: spacefractal on 2013-Feb-17

Title: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: spacefractal on 2013-Feb-17
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.
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: kanonet on 2013-Feb-17
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
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: spacefractal on 2013-Feb-17
I know and do that, but it's should still tracked by glbasic own. So hence it's a little request, not a bug  :)
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: kanonet on 2013-Feb-17
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.
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: fuzzy70 on 2013-Feb-17
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
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: MrTAToad on 2013-Mar-02
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)
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: spacefractal on 2013-Mar-08
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...
Title: Re: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: spacefractal on 2013-Mar-09
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".
Title: GETSPRITESIZE img, width%%, height%%, animframes%%
Post by: Kitty Hello on 2013-Mar-09
Is there a command setanim? I think so. You need some getanim to get the applied anim params then. No big deal.