Any way to change a sprites draw position

Previous topic - Next topic

okee

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
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

matchy

Use GRABSPRITE to a temporary sprite ID and draw that!

Moru

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 :-)

doimus

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

okee

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.
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)