Append tiles to already loaded anim variable.

Previous topic - Next topic

onumad

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!

Kitty Hello

Make your own. Sprite2mem and reverse.

BdR

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?

onumad

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

Slydog

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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

Quote from: onumad 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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

onumad

First of all, sorry for my bad english :-[
Quote from: Slydog on 2012-Apr-11
"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)

Quote from: Slydog on 2012-Apr-11
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)
Quote from: Slydog on 2012-Apr-11
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.
Quote from: Slydog on 2012-Apr-11
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)

onumad

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 ***

[attachment deleted by admin]

Kitty Hello

buggy example. must be:
MEM2SPRITE( pix%[], 0, w%, h%)