GLBasic forum

Main forum => GLBasic - en => Topic started by: Hark0 on 2013-Sep-06

Title: SOLVED: Polyvector TX,TY Offset howto?
Post by: Hark0 on 2013-Sep-06
Hi, I want to make my own ZOOMANIM function:

I'm use this, but ONLY is valid for a ONE row sprite anim:

Code (glbasic) Select

LOCAL Tile=30
LOCAL Escala=Zoom*Tile
LOCAL Origen=Sprite*Tile

STARTPOLY Anim
POLYVECTOR PosX+0, PosY+0 ,0+Origen ,0
POLYVECTOR PosX+0, PosY+Escala ,0+Origen ,Tile
POLYVECTOR PosX+Escala, PosY+Escala ,Tile+Origen ,Tile
POLYVECTOR PosX+Escala, PosY+0 ,Tile+Origen ,0
ENDPOLY


Any have the same func but for load any sprite of anim?

In the anim attached I want use func like ZOOMANIM anim,sprite,x,y,zoom...

When blue sprite are number 2... in the image attached for example.

Thanks!

Title: Re: Polyvector TX,TY howto?
Post by: mentalthink on 2013-Sep-06
I don't understand too much?¿, you want make an animation whit polyvector, (like drawanim?¿) if is this I think the easy way, use different sprites then you make a counter, passing each image (equal size) to the polyvector...

Anotherway using atlas image I think you have to changw the UV to the correct position in the image... (I think if you multiply x 2 and you image it's in square shape , have to works)

Something doing a counter...
number it's a counter

If number>size1
  uv=uv*2
else
number=0
posuv=1
endif

if posuv=1 and number>size1
Title: Re: Polyvector TX,TY howto?
Post by: mentalthink on 2013-Sep-06
I don't understand too much?¿, you want make an animation whit polyvector, (like drawanim?¿) if is this I think the easy way, use different sprites then you make a counter, passing each image (equal size) to the polyvector...

Anotherway using atlas image I think you have to changw the UV to the correct position in the image... (I think if you multiply x 2 and you image it's in square shape , have to works)

Title: Re: Polyvector TX,TY howto?
Post by: Hark0 on 2013-Sep-06
My question are:

If I pass to function a Sprite Number of a Anim.... How find the correct TX,TY posision on Anim for use with POLYVECTOR?

In other words:

Sprite 0 (red) of sample are TX=0, TY=0
Sprite 1 (green) of sample are TX=30, TY=0

and Sprite 2 (blue) and 3(violet)?
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: Hark0 on 2013-Sep-06
Hi, searching on Forum and making some test, this is a valid ZOOMANIM function.

Code (glbasic) Select
FUNCTION ZOOMANIM: Anim,Sprite,PosX,PosY,Zoom
LOCAL Tile=30
LOCAL Escala=Zoom*Tile
LOCAL sx,sy,cols,tx,ty

GETSPRITESIZE Anim, sx, sy
cols = INTEGER(sx / Tile)
    tx = MOD(Sprite, cols) * Tile
    ty = INTEGER(Sprite/cols) * Tile

STARTPOLY Anim
POLYVECTOR PosX+0, PosY+0 ,tx ,ty
POLYVECTOR PosX+0, PosY+Escala ,tx ,ty+Tile
POLYVECTOR PosX+Escala, PosY+Escala ,tx+Tile ,ty+Tile
POLYVECTOR PosX+Escala, PosY+0 ,tx+Tile ,ty
ENDPOLY

ENDFUNCTION


WARNING! This code is valid for a 30x30px Tile... Change value of Tile for other sizes...

You can use this function ZOOMANIM: Animation,SpriteNumber,PosX_Screen,PosY_Screen,Zoom_Factor

Zoom_Factor 1 -> 100%
Zoom_Factor 2 -> 200%
etc...

;)
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: mentalthink on 2013-Sep-06
Ok Hark, I don't know if putted, but I do whit a counter  O_O, but I look the another code I think it's better , whit the mathematical tricks.  :good: thanks for the search.
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: MrTAToad on 2013-Sep-06
Is it faster than ZOOMSPRITE ?
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: Hark0 on 2013-Sep-07
Quote from: MrTAToad on 2013-Sep-06
Is it faster than ZOOMSPRITE ?

I don't know... I need a ZOOM Animation (GLB not have this func), not a Zoomsprite  :P
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: mentalthink on 2013-Sep-07
A question guys, when MrT question about the speed, how do you do for easure the speed of some comands... I read similar questions sometimes, but really I don't know how you measure the command speeds, whit counters and prints,or GLbasic have something internal in Debug or something like that?¿...

Thanks and sorry for the  :offtopic:
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: MrTAToad on 2013-Sep-07
Quote from: Hark0 on 2013-Sep-07
Quote from: MrTAToad on 2013-Sep-06
Is it faster than ZOOMSPRITE ?

I don't know... I need a ZOOM Animation (GLB not have this func), not a Zoomsprite  :P
Yes, I meant ROTOZOOMSPRITE :)
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: MrTAToad on 2013-Sep-07
Quote from: mentalthink on 2013-Sep-07
A question guys, when MrT question about the speed, how do you do for easure the speed of some comands... I read similar questions sometimes, but really I don't know how you measure the command speeds, whit counters and prints,or GLbasic have something internal in Debug or something like that?¿...

Thanks and sorry for the  :offtopic:
Usually you need to measure how quickly the command completes.  However, it does need to be compared to ROTOZOOMSPRITE.  Essentially, you get the GETTIMERALL() value before the function starts, get it after and subtract the difference.  The lower the value, the quicker the operation.

You do need to do it for, say, 100 times (and average out the result), as Windows is a multi-tasking system and of course various things can affect the program.
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: mentalthink on 2013-Sep-07
Thanks Mrtatoad (I think I have to review the help, a lot fo commands I forget it), thanks in advance  :booze:
Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: fuzzy70 on 2013-Sep-07
Technically you cannot compare the speed against ROTOZOOMSPRITE as it has no support for sprites loaded with LOADANIM, which is the reason why this code was posted.

Sure you can compare it speedwise to a single sprite but the result is meaningless due to the different functionality.

Polyvectors are slower on some platforms (like cannoo etc I think & maybe older android devices)

Lee

Sent from my Xperia Z using Tapatalk 2

Title: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: MrTAToad on 2013-Sep-07
In which case you would compare it with ROTOZOOMANIM...
Title: Re: Re: SOLVED: Polyvector TX,TY Offset howto?
Post by: fuzzy70 on 2013-Sep-07
Quote from: MrTAToad on 2013-Sep-07
In which case you would compare it with ROTOZOOMANIM...
True, I don't use any of the anim commands as I roll my own & was unaware ROTOZOOMANIM even existed. I presumed it didn't exist hence the reason for the original post.

Lee

Sent from my Xperia Z using Tapatalk 2