alternative to grabsprite???

Previous topic - Next topic

phaelax

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?

MrTAToad

It sounds like you need LOADANIM/DRAWANIM to split a sprite into rectangles which can be displayed individually.

Ian Price

You can use a virtual screen that is larger than the real screen resolution and draw on that -

Code (glbasic) Select

// 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.
I came. I saw. I played.

Cliff3D

Oooh, that looks handy! Should both Usescreen lines have a paramter of 0 though?

MrTAToad

#4
USESCREEN of -1 reverts back to the standard backbuffer, and not your newly created screen.

phaelax

#5
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.

Wampus

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.  :)

Ian Price

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.
I came. I saw. I played.

Cliff3D

What I was referring to was this:

Quote from: Ian Price on 2010-Sep-09
Code (glbasic) Select

...

// 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?

Ian Price

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
I came. I saw. I played.

Moru

Any special reason why you want to split it up instead of using DRAWANIM?

MrTAToad

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:

phaelax

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.

MrTAToad

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

Moru

LOADANIM and DRAWANIM is created exactly for this purpose, no need to grab single sprites any more.