I have a function for grabbing individual tiles from a larger tileset image, function looks something like this:
loadsprite path$, 0
drawsprite 0,0,0
//routine for grabbing individual sprites
The problem I've noticed is that it can only grab what fits within the screen's resolution. I suppose a work around could be offsetting the tileset sprite as I grab each tile. Is there a way to read the image data directly from memory and rebuild each tile that way?
It sounds like you need LOADANIM/DRAWANIM to split a sprite into rectangles which can be displayed individually.
You can use a virtual screen that is larger than the real screen resolution and draw on that -
// Set physical screen resolution
SETSCREEN 640, 480, 0
// Create a virtual screen that is larger than the physical screen
CREATESCREEN 0,999,1024,768
// Do all actions on the virtual screen
USESCREEN 0
// Draw lots of random rectangles on the virtual screen
FOR n=0 TO 1000
DRAWRECT RND(1024),RND(768),RND(64),RND(64),RGB(RND(255),RND(255),RND(255))
NEXT
// Grab a portion of the virtual screen
GRABSPRITE 1,800,100,128,128
// Use the normal, visible screen
USESCREEN 0
// Main loop
// Repeat until ESC pressed
WHILE TRUE
// Show portion
DRAWSPRITE 1,100,100
// Refresh everything
SHOWSCREEN
// Repeat the main loop unless condition is broken (ESC pressed)
WEND
END
The example above draws on the virtual screen and grabs a portion of it that is beyond the 640x480 limit of the actual screen, then displays it in the main loop.
Or do exactly what Mr taToad suggest and use LOADANIM.
Oooh, that looks handy! Should both Usescreen lines have a paramter of 0 though?
USESCREEN of -1 reverts back to the standard backbuffer, and not your newly created screen.
this virtual screen doesn't have to fit to the resolution limits of a graphics card does it?
Also, I couldn't find any kind of delete sprite command. Once I've split the image up, I don't need to keep it loaded anymore so it'd be nice if I could free up the memory.
Quote from: phaelax on 2010-Sep-09
Also, I couldn't find any kind of delete sprite command. Once I've split the image up, I don't need to keep it loaded anymore so it'd be nice if I could free up the memory.
Trying to load a file that doesn't exist using the same ID as the sprite you want deleted will work. For example, use the command
LOADSPRITE "nofile", n where n is the ID of the sprite you want deleted.
BTW the virtual screen might be a problem if it exceeds the GPU memory. Only one way to find out and that's to try it for yourself. :)
Quote from: MrTAToad on 2010-Sep-09
USESCREEN of 0 reverts back to the standard backbuffer, and not your newly created screen.
Actually the standard backbuffer is -1, not 0.
In that example 0 is the virtual screen.
What I was referring to was this:
Quote from: Ian Price on 2010-Sep-09
...
// Do all actions on the virtual screen
USESCREEN 0
...
// Use the normal, visible screen
USESCREEN 0
It seemed likely to me that the second USESCREEN should be USESCREEN -1, but I was perhaps being too timid?
QuoteIt seemed likely to me that the second USESCREEN should be USESCREEN -1, but I was perhaps being too timid?
Ah yes, Cliff3D - thanks for noticing my deliberate mistake! :P It was late at night and I'd just finished work.
It's funny, but the code worked fine, but really it shouldn't! It shouldn't draw the sprite at all as the code has requested to draw to the virtual screen, not the actual one. Bonkers. :S
Any special reason why you want to split it up instead of using DRAWANIM?
Quote from: Ian Price on 2010-Sep-09
Quote from: MrTAToad on 2010-Sep-09
USESCREEN of 0 reverts back to the standard backbuffer, and not your newly created screen.
Actually the standard backbuffer is -1, not 0.
In that example 0 is the virtual screen.
Thats quite true :whistle:
QuoteAny special reason why you want to split it up instead of using DRAWANIM?
I suppose I could use grabsprite with drawanim. I need each individual tile from the image because they're tiles for a map, not just a single character animation.
You wont need to use GRABSPRITE with DRAWANIM - just use LOADANIM (or LOADSPRITE with another command that I cant remember) and let DRAWANIM split the tiles for display
LOADANIM and DRAWANIM is created exactly for this purpose, no need to grab single sprites any more.