Author Topic: Append tiles to already loaded anim variable.  (Read 308 times)

Offline onumad

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
I have 2 tiles files (Tiles001.png and Tiles002.png)

Is there  any way to add the tiles of the second image to the variable 'ani_base'?

Code: GLBasic [Select]
LOADANIM "../tiles/Tiles001.png", ani_base, sizesprites48, sizesprites48

Something as:
Code: GLBasic [Select]
APPENDANIM "../tiles/Tiles002.png", ani_base, sizesprites48, sizesprites48

Thank you!

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10294
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Append tiles to already loaded anim variable.
« Reply #1 on: 2012-Apr-11 »
Make your own. Sprite2mem and reverse.

Offline BdR

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
    • BdR Games
Re: Append tiles to already loaded anim variable.
« Reply #2 on: 2012-Apr-11 »
Why not make a 48x96 image with the two sprites and then just use LOADANIM? O_O Or do you want different combinations of images in an animation, each time different images?

Offline onumad

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
Re: Append tiles to already loaded anim variable.
« Reply #3 on: 2012-Apr-11 »
Yes Bdr, I'm using Tiled map editor with more than one tileset images

Kitty, yes, I'll play with Sprite2men. I did not want to reinvent the wheel

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 807
  • KodeSource
    • View Profile
    • KodeSource
Re: Append tiles to already loaded anim variable.
« Reply #4 on: 2012-Apr-11 »
Unfortunately, LOADANIM (and DRAWANIM) only work when the sprite file contains ALL of the frames needed.
If you are working from a set of sprite files, each containing ONE tile image, then those commands wont work for you.

You can manually create one large sprite file that contains ALL tile images, then those commands will work.

Or, have a routine (that runs once at program start) that loads each sprite tile (using LOADSPRITE) and dynamically create a new sprite and paste each tile into this new sprite.  Save this new sprite to disk using SAVESPRITE.  Then load this new sprite file (containing all of your tiles) using LOADANIM.  This lets you just manage a bunch of individual sprite files and not worry about packing them into a sprite sheet (by having your program create this sprite sheet for you).

Or, don't use LOADANIM, but only use a bunch of LOADSPRITE commands, and manually manage your sprite animation.  You could build a custom sprite animation TYPE and include methods such as: SETSPEED, PLAYREVERSE, SCALE, etc.  This will give you absolute control of the sprite animation.  The advantage to this method is that eventually if you want to compile your game for a production release, you probably don't want to be using those built in sprite commands anyways.  You'll want to update your sprite displaying to use POLYVECTORs, for increased speed.  Unless this is a very simple game were performance isn't a problem.
« Last Edit: 2012-Apr-11 by Slydog »
- Do pessimistic cats have 9 deaths?

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 807
  • KodeSource
    • View Profile
    • KodeSource
Re: Append tiles to already loaded anim variable.
« Reply #5 on: 2012-Apr-11 »
Yes Bdr, I'm using Tiled map editor with more than one tileset images

I'm not too sure what you mean by this.
Tiled lets you use a tileset / sprite sheet as a source for the tile images correct?
(as opposed to ONLY allowing you to load each tile image from a separate file)

"more than one tileset images": do you mean more than one tile image, or more than one tileset?
ie, Mario has different worlds / themes.  Each theme would be a different tileset, containing multiple tiles.
So when editing a level in Tiled, you first load a theme tileset file (one file containg all tiles for that theme).
Then edit your level.  Later you can change the theme of this level by just loading in a different tileset theme.
Each theme is just one file, therefore LOADANIM should work fine for this.

I can't think of a situation where you can't create a tileset sprite file containing all of your tiles.
Maybe for a random world where you don't know what tiles are to be included ahead of playing the level.

BTW, can Tiled have animated tiles, such as walls?  That would be a neat concept I've never considered.
If your level has static tiles, and only your characters / items need animation, you could separate your sprites into two or more files, one for the level tiles, and one for your character/item animations.
- Do pessimistic cats have 9 deaths?

Offline onumad

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
Re: Append tiles to already loaded anim variable.
« Reply #6 on: 2012-Apr-11 »
First of all, sorry for my bad english :-[
"more than one tileset images": do you mean more than one tile image, or more than one tileset?...
more than one tile images for the same map (I put tileA.png, tileB, png.... and Tiled creates a diferent tileset per image file)

I can't think of a situation where you can't create a tileset sprite file containing all of your tiles.
well, I'm not sure for now what tiles will use so I loaded 6 diferent files (one per tileset)
BTW, can Tiled have animated tiles, such as walls?  That would be a neat concept I've never considered.
I don't know, I installed Tiled this monday.
If your level has static tiles, and only your characters / items need animation, you could separate your sprites into two or more files, one for the level tiles, and one for your character/item animations.
Yes, I always do it as you said. But I never used Tiled (always Mappy with unique tileset)

Offline onumad

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
Re: Append tiles to already loaded anim variable.
« Reply #7 on: 2012-Apr-11 »
Now, why GLBasic raise this error with the LOADSPRITEMEM example?
Code: GLBasic [Select]
// --------------------------------- //
// Project: spr2mem2file
// Start: Wednesday, April 11, 2012
// IDE Version: 10.283
// SETCURRENTDIR("Media") // go to media files

LOCAL w%, h%, pix%[]
IF LOADSPRITEMEM("d:/tiles.png", w%, h%, pix%[])
   MEM2SPRITE(0, w%, h%, pix%[])
   DRAWSPRITE 0,0,0
ENDIF
SHOWSCREEN
MOUSEWAIT

Quote
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.9.829 SN:349f8813 - 3D, NET
Wordcount:8 commands
compiling:
C:\Users\ZIKIAD~1\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\ZIKIAD~1\AppData\Local\Temp\glbasic\gpc_temp0.cpp:60: error: invalid initialization of non-const reference of type '__GLBASIC__::DGNatArray&' from a temporary of type 'int'
D:/program/GLBasic/Compiler/platform/Include/glb.h:1339: error: in passing argument 1 of `DGNat __GLBASIC__::MEM2SPRITE(__GLBASIC__::DGNatArray&, DGNat, DGNat, DGNat)'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.1 sec. Time: 23:17
Build: 0 succeeded.
*** 1 FAILED ***

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *****
  • Posts: 10294
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Append tiles to already loaded anim variable.
« Reply #8 on: 2012-Apr-11 »
buggy example. must be:
MEM2SPRITE( pix%[], 0, w%, h%)