Author Topic: How to detect a TILE size?  (Read 4206 times)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3679
    • View Profile
    • Space Fractal
How to detect a TILE size?
« 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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

MrTAToad

  • Guest
Re: How to detect a TILE size?
« Reply #1 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.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3679
    • View Profile
    • Space Fractal
Re: How to detect a TILE size?
« Reply #2 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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

MrTAToad

  • Guest
Re: How to detect a TILE size?
« Reply #3 on: 2011-May-12 »
Sounds like the way to do it.

Offline XanthorXIII

  • Mr. Polyvector
  • ***
  • Posts: 197
    • View Profile
Re: How to detect a TILE size?
« Reply #4 on: 2011-May-12 »
How about GETSPRITE with a combination of calculations of what the size of each tile should be?
Owlcat has wise

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4218
    • View Profile
    • Portfolio
Re: How to detect a TILE size?
« Reply #5 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.

MrTAToad

  • Guest
Re: How to detect a TILE size?
« Reply #6 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

Offline XanthorXIII

  • Mr. Polyvector
  • ***
  • Posts: 197
    • View Profile
Re: How to detect a TILE size?
« Reply #7 on: 2011-May-16 »
spacefractal - You're using Sprite Sheets correct?
Owlcat has wise

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: How to detect a TILE size?
« Reply #8 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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3679
    • View Profile
    • Space Fractal
Re: How to detect a TILE size?
« Reply #9 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.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.