Author Topic: alternative to grabsprite???  (Read 2677 times)

Offline phaelax

  • Mc. Print
  • *
  • Posts: 36
    • View Profile
alternative to grabsprite???
« on: 2010-Sep-08 »
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

  • Guest
Re: alternative to grabsprite???
« Reply #1 on: 2010-Sep-09 »
It sounds like you need LOADANIM/DRAWANIM to split a sprite into rectangles which can be displayed individually.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4144
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: alternative to grabsprite???
« Reply #2 on: 2010-Sep-09 »
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.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Re: alternative to grabsprite???
« Reply #3 on: 2010-Sep-09 »
Oooh, that looks handy! Should both Usescreen lines have a paramter of 0 though?

MrTAToad

  • Guest
Re: alternative to grabsprite???
« Reply #4 on: 2010-Sep-09 »
USESCREEN of -1 reverts back to the standard backbuffer, and not your newly created screen.
« Last Edit: 2010-Sep-14 by Kitty Hello »

Offline phaelax

  • Mc. Print
  • *
  • Posts: 36
    • View Profile
Re: alternative to grabsprite???
« Reply #5 on: 2010-Sep-09 »
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.
« Last Edit: 2010-Sep-09 by phaelax »

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: alternative to grabsprite???
« Reply #6 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.  :)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4144
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: alternative to grabsprite???
« Reply #7 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.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Re: alternative to grabsprite???
« Reply #8 on: 2010-Sep-09 »
What I was referring to was this:

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?

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4144
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: alternative to grabsprite???
« Reply #9 on: 2010-Sep-09 »
Quote
It 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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: alternative to grabsprite???
« Reply #10 on: 2010-Sep-09 »
Any special reason why you want to split it up instead of using DRAWANIM?

MrTAToad

  • Guest
Re: alternative to grabsprite???
« Reply #11 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:

Offline phaelax

  • Mc. Print
  • *
  • Posts: 36
    • View Profile
Re: alternative to grabsprite???
« Reply #12 on: 2010-Sep-10 »
Quote
Any 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

  • Guest
Re: alternative to grabsprite???
« Reply #13 on: 2010-Sep-10 »
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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: alternative to grabsprite???
« Reply #14 on: 2010-Sep-10 »
LOADANIM and DRAWANIM is created exactly for this purpose, no need to grab single sprites any more.