GLBasic forum

Main forum => GLBasic - en => Topic started by: fuzzy70 on 2012-Mar-16

Title: Sprite handles
Post by: fuzzy70 on 2012-Mar-16
Is there a command to change the X & Y handles of a sprite. From what I have made out DRAWSPRITE uses the top left corner (0,0) of the sprite for it's drawing whereas ROTOSPRITE uses the centre of the sprite. Basically I want to rotate around a certain point & not the middle of the image.

If it means me making a routine using polyvectors then that's not a problem but I thought I would check before re-inventing the wheel so to speak  :D

Lee
Title: Re: Sprite handles
Post by: MrTAToad on 2012-Mar-16
No, it would be nice if there was, but you need to calculate it all yourself.  I borrowed this from the oSprite routine :

Code (glbasic) Select
FUNCTION DrawSpr_Scale%:spriteID%,spriteIndex%,x,y,angle,scale,useScale%=TRUE
LOCAL cosp,sinp,sx,sy,px,py,rx,ry

IF useScale%=TRUE
scale=scale*self.maxScale
ENDIF

cosp=COS(angle)
    sinp=SIN(angle)

    sx = self.spriteLoadData[spriteID%].xSize%/2.0
    sy = self.spriteLoadData[spriteID%].ySize%/2.0

// Always revolve around the centre
    px = self.spriteLoadData[spriteID%].handleXOffset%-sx
    py = self.spriteLoadData[spriteID%].handleYOffset%-sy

    // reverse rotate pivot point around center
    // of sprite
    rx = (px*cosp + py*sinp) * scale
    ry = (py*cosp - px*sinp) * scale

    // adjust center
    INC rx,sx
    INC ry,sy

IF spriteIndex%<0
    ROTOZOOMSPRITE self.spriteLoadData[spriteID%].idNumber%,x-rx,y-ry,angle,scale
    ELSE
    ROTOZOOMANIM self.spriteLoadData[spriteID%].idNumber%,spriteIndex%,x-rx,y-ry,angle,scale
    ENDIF
ENDFUNCTION
Title: Re: Sprite handles
Post by: fuzzy70 on 2012-Mar-16
Thanks for that, will have a play. I can figure out the references to the TYPE that was used  =D

Lee
Title: Re: Sprite handles
Post by: spacefractal on 2012-Mar-16
Actuelly I have really nightmare just because that center hotspot in Greedy Mouse and took long time to place those thing top left and fix eventuelly scaling issues (even rotating was not used), that allways do some strange thing. So its absolute not easy at all, unlike blitzmax.

So in the request thing, a HOTSPOT x,y would been really cool to have and some thing could been much easier. Howover its could of course been in a type really :-D.