GLBasic forum

Main forum => GLBasic - en => Topic started by: okee on 2010-Apr-14

Title: Any way to change a sprites draw position
Post by: okee on 2010-Apr-14
is there a command to set the point on a sprite that it draws from ?
i.e normally it'll draw the sprite from 0,0 but i would like the drawing position
to be the centre or 10,10 etc

Thanks

okee
Title: Re: Any way to change a sprites draw position
Post by: matchy on 2010-Apr-14
Use GRABSPRITE to a temporary sprite ID and draw that!
Title: Re: Any way to change a sprites draw position
Post by: Moru on 2010-Apr-14
You can make a simple function that draws the sprite on whatever hotspot you want. Use GETSPRITESIZE to get the size of the sprite


Code (glbasic) Select
FUNCTION DrawSprite2: id, x, y
LOCAL w, h
LOCAL hotspotx, hotspoty

GETSPRITESIZE id, w, h

IF w>0 AND h>0
// If you want centered hotspot:
hotspotx = w/2
hotspoty = h/2

// New position of draw
x = x - hotspotx
y = y - hotspoty
DRAWSPRITE id, x, y
ENDIF
ENDFUNCTION


(untested :-)
Title: Re: Any way to change a sprites draw position
Post by: doimus on 2010-Apr-14
I usually keep my sprites in types - something like objects, characters, etc.

Then I put offset x/y field in type definitions for exactly these purposes. Basically a variation of what Moru said.
Code (glbasic) Select

character AS TCharacter

character.offset_x = 16
character.offset_y = 32

num = character.spritenum
x = x - character.offset_x
y = y - character.offset_y

DRAWSPRITE num, x, y
Title: Re: Any way to change a sprites draw position
Post by: okee on 2010-Apr-15
Yeah I'm using types anyway the store the objects so shouldn't be too much trouble adjust their
draw coordinates, just thought there might be some command i was overlooking.