GLBasic forum

Main forum => Tutorials => Topic started by: spacefractal on 2011-May-12

Title: How to detect a TILE size?
Post by: spacefractal on 2011-May-12
I want to get the size of the tile of a anim, but have a problem.

If I use GETSPRITESIZE i got the whole image size, rather than tile size as I want.

So GETSPRITESIZE object, w, h is not a option at all when using anim.

This is due STRETCHANIM command want to known its size, rather than using procent like other commands does. That is really dumb, when the app dont known the size of it and then it would been fussy.

Also STRETCHANIM use current size rather than using procents, like other commands do.

I trying to just mirror a animated sprite (in one axis), using its current tile size.
Title: Re: How to detect a TILE size?
Post by: MrTAToad on 2011-May-12
If you use LOADANIM you can use the values you give that.

If you use LOADSPRITE and then want to use SETSPRITEANIM, as long as you know how many tiles are across and down, you can then work out the tile size.
Title: Re: How to detect a TILE size?
Post by: spacefractal on 2011-May-12
the issue is the what I coded the "paint()" part is, the woudl been much easier if its could return the tile info with such of command. Look like I need create a little list with object sizes instead.
Title: Re: How to detect a TILE size?
Post by: MrTAToad on 2011-May-12
Sounds like the way to do it.
Title: Re: How to detect a TILE size?
Post by: XanthorXIII on 2011-May-12
How about GETSPRITE with a combination of calculations of what the size of each tile should be?
Title: Re: How to detect a TILE size?
Post by: erico on 2011-May-12
can´t you also have a red dot on the lower right corner of each sprite? and them check for this dot color to find out the size?
although if you resize it all I guess it won´t work...

...XanthorXIII´s plan sounds better.
Title: Re: How to detect a TILE size?
Post by: MrTAToad on 2011-May-13
You could scan horizontally and vertically looking for a colour, and then continue from that and grab a rectangular area based on the coordinates given - the Amiga version of BlitzBasic would do that to grab sprites
Title: Re: How to detect a TILE size?
Post by: XanthorXIII on 2011-May-16
spacefractal - You're using Sprite Sheets correct?
Title: Re: How to detect a TILE size?
Post by: Slydog on 2011-May-16
Quote from: XanthorXIII on 2011-May-16
spacefractal - You're using Sprite Sheets correct?

That's what I was wondering.
If so, and you used the 'LOADANIM()' command, you already know the tile size, as that's a parameter to the command.
Unless you've loaded multiple sprite sheets using this command and you no longer have access to the tile size info for a specific sprite.

If this is the case then I would recommend creating a 'SPRITE' type (or 'ANIMATION' type).
This would store your spite and animation info, such as tile size.

Code (glbasic) Select
TYPE TAnimation
  sprite_id%
  tile_size_w%
  tile_size_h%

  FUNCTION Load: fileName$, tile_size_w%, tile_size_h%
    self.sprite_id = SpriteIdNew()
    self.tile_size_w = tile_size_w
    self.tile_size_h = tile_size_h
    LOADANIM fileName$, self.sprite_id, tile_size_w, tile_size_h
  ENDFUNCTION

  FUNCTION Draw: frame%, x%, y%
    DRAWANIM self.sprite_id, frame, x, y
  ENDFUNCTION
ENDTYPE

FUNCTION SpriteIdNew%:
  STATIC sprite_id% = 1000
  INC sprite_id
  RETURN sprite_id
ENDFUNCTION

//Usage:
LOCAL anim AS TAnimation
anim.Load("sprite_sheet.png", 32, 32)
anim.Draw(1, 100, 100)
width = anim.tile_size_w


This is just for example, this code may not work, just made it up.
Title: Re: How to detect a TILE size?
Post by: spacefractal on 2011-May-18
Yes its somewhere extractly that I did (Slydos code), because I use varied in sizes animation, and the code very separate the update() and paint() completly. So I need just to add 2 new variables to the struct. But would been lots easier to just detect it when paint a image (via a function of course, not directly), due that way I have coded it.

I do still wonder, but this is more a request, so hence not a bug or something like that.