Author Topic: Any way to change a sprites draw position  (Read 2078 times)

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
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)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: Any way to change a sprites draw position
« Reply #1 on: 2010-Apr-14 »
Use GRABSPRITE to a temporary sprite ID and draw that!

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Any way to change a sprites draw position
« Reply #2 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 :-)

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: Any way to change a sprites draw position
« Reply #3 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

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Any way to change a sprites draw position
« Reply #4 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.
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)