LoadAnim and DrawAnim?

Previous topic - Next topic

Amon

These are confusing me. Can anyone show how they are used properly?

Here's my problem. My animstrip is laid out as follows:

####
##

The tiles are 25px by 25px. When I use DrawAnim to draw cell 4 it just closes to the desktop.

DRAWANIM 0,4,xiter * TileWidthHeight, yiter * TileWidthHeight

Ta!
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

MrTAToad

Is there the graphic file 100 x 50?

matchy

First frame is 0, last is 3.

Amon

Still confused. :)

I've attached the graphic file. My Loadanim command looks like this:   LOADANIM "tileset.png",0,25,25



[attachment deleted by admin]
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

FutureCow

Amon,
The tiles in your animstrip are numbered as follows

0,1,2,3
4,5,6,7

Even though 6,7 may not have anything in them, they will be loaded anyway.
Assuming your anim graphic is 4 tiles wide, by two high (as per the diagram) - and therefore there IS a tile 4 (ie. the fifth tile / the first one on the second row - as tiles are numbered from 0), this shouldn't crash your program.

My suggestions :
* Have you verified that you are compiling for the right operating system / right sized desktop in the project configuration options?
* Make sure Debug is turned on and run it again
* Instead of
Code (glbasic) Select
DRAWANIM 0,4,xiter * TileWidthHeight, yiter * TileWidthHeight did you actually mean
Code (glbasic) Select
DRAWANIM 0,4,xiter * TileWidth, yiter * TileHeight
* Do all the other tiles work?
ie. what happens if you change your code to
Code (glbasic) Select

DRAWANIM 0,0,0, 0
DRAWANIM 0,1,0, TileWidthHeight
DRAWANIM 0,2,0, 2 * TileWidthHeight
DRAWANIM 0,3,0, 3 * TileWidthHeight
DRAWANIM 0,5,0, 4 * TileWidthHeight

This will show up whether you're actually loading the file you're trying to display tiles from (for example you won't get an error if loadanim doesn't load the file - but you might when you try to display part of it), ensure you haven't accidently changed the value of your TileWidthHeight variable, or whether there's a problem with that actual bitmap
* If none of the tiles display, ensure you've saved the file as a bmp or png
* If all the above doesn't suggest the cause, post all your code here (or the smallest part of it that can be run to replicate the crash) and we'll see what else we can suggest

FutureCow

Also, when you turn on debug, put this line of code before your drawanim
Code (glbasic) Select
debug "xiter = " + xiter + "  yiter = " + yiter + " TileWidthHeight = " + TileWidthHeight + "\n"

Neurox

Hi,
I've tested and... run ;)

Code (glbasic) Select

LOADANIM "tileset.png", 1, 25,25
WHILE TRUE
   FOR i=0 TO 7
      DRAWANIM 1, i, 10,10
      PRINT "Press any key, but not ESCape ;-)",10,40
      SHOWSCREEN
      KEYWAIT
   NEXT
WEND
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Amon

Hi Guys. It all seems to crash out when i try drawing the 4th image. Using futurecows code bit it works fien so there is a definite error in my code. The code is a simple single screen (Beginings of) map editor. code below.  Thanks for helping by the way. :)

Code (glbasic) Select

// --------------------------------- //
// Project: SSMapEditor (Single Screen Map Editor) By Amon - No Save possible
// Save Coming in Version 2
// Start: Sunday, December 27, 2009
// IDE Version: 7.203


SETCURRENTDIR("Media") // seperate media and binaries?
LOADANIM "tileset.png",0,25,25


SETSCREEN 800,600,0


CurrentTile = 0

MAPWIDTH = 32 // MapWidth
MAPHEIGHT = 24 // MapHeight

TileWidthHeight = 25

GLOBAL MouseX, MouseY,MB1,MB2

DIM Map#[MAPWIDTH][MAPHEIGHT]

FOR x1 = 0 TO MAPWIDTH - 1
FOR y1 = 0 TO MAPHEIGHT - 1
Map[x1][y1] = 3 //RND(4)
NEXT
NEXT


WHILE KEY(01) = 0

BLACKSCREEN

// FillMap()
// DrawMap()
DRAWANIM 0,0,0, 0
DRAWANIM 0,1,0, TileWidthHeight
DRAWANIM 0,2,0, 2 * TileWidthHeight
DRAWANIM 0,3,0, 3 * TileWidthHeight
DRAWANIM 0,4,0, 4 * TileWidthHeight
DRAWANIM 0,5,0, 5 * TileWidthHeight


SHOWSCREEN
WEND

FUNCTION DrawMap:
FOR xiter = 0 TO MAPWIDTH -1
FOR yiter = 0 TO MAPHEIGHT - 1
IF Map[xiter][yiter] = 0
DRAWANIM 0,0,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 1
DRAWANIM 0,1,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 2
DRAWANIM 0,2,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 3
DRAWANIM 0,3,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 4
DRAWANIM 0,4,xiter * TileWidthHeight, yiter * TileWidthHeight
END
IF Map[xiter][yiter] = 5 THEN
DRAWANIM 0,5,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
NEXT
NEXT
ENDFUNCTION

FUNCTION FillMap:
IF KEY(57) = 1
CurrentTile = CurrentTile + 1
IF CurrentTile >5 THEN CurrentTile = 0
ENDIF

MOUSESTATE MouseX, MouseY, MB1, MB2

IF MB1 = 1
Map[MouseX/TileWidthHeight][MouseY/TileWidthHeight] = CurrentTile
ENDIF



ENDFUNCTION
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Amon

#8
Arghhh, there was a pretty bad typo in my code, maybe due to how late it was. I've got it working now. :)

Basicaly it was an ENDIF/Then issue. :)

Here's the final code: It's basically a simple method to draw tilemaps. I'll work on a saving and loading routine now. :)

Code (glbasic) Select
// --------------------------------- //
// Project: SSMapEditor (Single Screen Map Editor) By Amon - No Save possible
// Save Coming in Version 2
// Start: Sunday, December 27, 2009
// IDE Version: 7.203


SETCURRENTDIR("Media") // seperate media and binaries?
LOADANIM "tileset.png",0,25,25
LOADSPRITE "arrow.png",1

SETSCREEN 800,600,0


CurrentTile = 0

MAPWIDTH = 32 // MapWidth
MAPHEIGHT = 24 // MapHeight

TileWidthHeight = 25

GLOBAL MouseX, MouseY,MB1,MB2

DIM Map#[MAPWIDTH][MAPHEIGHT]

FOR x1 = 0 TO MAPWIDTH - 1
FOR y1 = 0 TO MAPHEIGHT - 1
Map[x1][y1] = RND(4)
NEXT
NEXT


WHILE KEY(01) = 0

BLACKSCREEN

FillMap()
DrawMap()
// DRAWANIM 0,0,0, 0
// DRAWANIM 0,1,0, TileWidthHeight
// DRAWANIM 0,2,0, 2 * TileWidthHeight
// DRAWANIM 0,3,0, 3 * TileWidthHeight
// DRAWANIM 0,4,0, 4 * TileWidthHeight
// DRAWANIM 0,5,0, 5 * TileWidthHeight

DRAWSPRITE 1,MouseX/MouseX*MouseX,MouseY/MouseY*MouseY

SHOWSCREEN
WEND

FUNCTION DrawMap:
FOR xiter = 0 TO MAPWIDTH -1
FOR yiter = 0 TO MAPHEIGHT - 1
IF Map[xiter][yiter] = 0
DRAWANIM 0,0,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 1
DRAWANIM 0,1,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 2
DRAWANIM 0,2,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 3
DRAWANIM 0,3,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 4
DRAWANIM 0,4,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF
IF Map[xiter][yiter] = 5
DRAWANIM 0,5,xiter * TileWidthHeight, yiter * TileWidthHeight
ENDIF

NEXT
NEXT
ENDFUNCTION

FUNCTION FillMap:
IF KEY(57) = 1
CurrentTile = CurrentTile + 1
IF CurrentTile >5 THEN CurrentTile = 0
ENDIF

MOUSESTATE MouseX, MouseY, MB1, MB2

IF MB1 = 1
Map[MouseX/TileWidthHeight][MouseY/TileWidthHeight] = CurrentTile
ENDIF

ENDFUNCTION


[attachment deleted by admin]
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!