BASIC

Author Topic: GETSPRITESIZE img, width%%, height%%, animframes%%  (Read 3654 times)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3482
    • View Profile
    • Space Fractal
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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
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

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3482
    • View Profile
    • Space Fractal
I know and do that, but it's should still tracked by glbasic own. So hence it's a little request, not a bug  :)
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
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

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
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

  • Guest
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)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3482
    • View Profile
    • Space Fractal
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...
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3482
    • View Profile
    • Space Fractal
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".
« Last Edit: 2013-Mar-09 by spacefractal »
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10661
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Is there a command setanim? I think so. You need some getanim to get the applied anim params then. No big deal.