Author Topic: How do you Paste a sprite?  (Read 2206 times)

Gerfy

  • Guest
How do you Paste a sprite?
« on: 2009-Aug-20 »
Maybe I'm overlooking a command somewhere, but I cant seem to find a way to paste a sprite into the screen. Dont want to draw.. because its for the background - just want to paste it either to the screen directly, or into the sprite I'm using to hold the background.

Thanks.
« Last Edit: 2009-Aug-20 by Gerfy »

Hatonastick

  • Guest
Re: How do you Paste a sprite?
« Reply #1 on: 2009-Aug-20 »
USESCREEN %id, if you are using CREATESCREEN to create a working area that isn't automatically displayed.  eg.

If the virtual screen was created using CREATESCREEN is screen 0:

USESCREEN 0
  Normal drawing commands here which are being rerouted to the virtual screen and not the screen about to be drawn ie. backbuffer.
USESCREEN -1

The USESCREEN -1 redirects things back to the backbuffer again, where they are normally drawn.  Instructions for all of this are under the CREATESCREEN command.  Well most of it is.  USESCREEN mentions what the -1 parameter does.

Otherwise I'm not really sure what you are trying to say, sorry.

Gerfy

  • Guest
Re: How do you Paste a sprite?
« Reply #2 on: 2009-Aug-20 »
Here's my code:

Code: GLBasic [Select]
FUNCTION setup_grid1:

        x1=0 ; y1=0
        RESTORE screen_grid

        FOR y=1 TO 12
        FOR x=1 TO 13

        READ screen[x][y]

        IF screen[x][y]<>0
        DRAWRECT x1,y1,39,39, RGB (0,50,50)
//      DRAWSPRITE 5,x1,y1
        ENDIF

        x1=x1+40
        NEXT
        x1=0; y1=y1+40
        NEXT
ENDFUNCTION

At the mo I'm blasting the screen with drawrect, which all works fine - but I want to paste sprites onto the screen. (a copy of sprite 5)

Hatonastick

  • Guest
Re: How do you Paste a sprite?
« Reply #3 on: 2009-Aug-20 »
You've still lost me.  Every time you call DRAWSPRITE 5 it should be drawing a copy of sprite #5 onto the screen (or virtual screen if you are using one and have redirected it).  If it isn't something is going wrong somewhere because that's how DRAWSPRITE works (last time I looked at it).  Actually I'm looking at one of the official examples right now that uses multiple drawings of a single sprite (eg. DRAWSPRITE 0 called multiple times) with different alpha settings to create the main sprite as well as a shadow.  So the command should be working.

DRAWSPRITE 5 would only draw one copy of sprite 5 if you updated the screen after every DRAWSPRITE call (but you don't seem to be doing that so that shouldn't be a problem).  If you call it multiple times before the screen being redrawn, such as in a loop, there should be multiple copies of the sprite on the screen.  At least I'm pretty sure that's the case.  Last time I looked at it DRAWSPRITE was basically pasting a copy of the sprite to the current screen.

Basically what I'm saying is from the code you've posted, if you uncommented the DRAWSPRITE call and commented out the DRAWRECT call (and providing there isn't an error somewhere else in code that you haven't posted), should do exactly what you are asking.  Since it obviously isn't, what is it doing exactly?  Drawing no sprites? Just drawing one sprite?  Drawing a few?
« Last Edit: 2009-Aug-20 by Hatonastick »

MrTAToad

  • Guest
Re: How do you Paste a sprite?
« Reply #4 on: 2009-Aug-20 »
If you just want a static background graphic, you could use LOADBMP

However, if you want to animate or move it, you will need to use DRAWSPRITE - but, as its the background, you will need to use it first.

Gerfy

  • Guest
Re: How do you Paste a sprite?
« Reply #5 on: 2009-Aug-20 »
Sorta got to the bottom of it.. I'm setting up my sprite thats being called in another function.

I'm guessing it wasnt passing the correct address or info to the setup_grid1 function. By putting the loadsprite command in the example I posted above - it all works.

So.. I cant use this function ? I wanted to keep all the sprite loading seperate from the main game functions.

Code: GLBasic [Select]
FUNCTION loadgrx:

        LOADSPRITE "grass.bmp", 5

ENDFUNCTION


I wanted to call the function that loads the sprites, then the function that sets up the display, finally it can carry on to the main game loop.

MrTAToad

  • Guest
Re: How do you Paste a sprite?
« Reply #6 on: 2009-Aug-20 »
Sure your actually calling the function before trying to draw everything ?

Gerfy

  • Guest
Re: How do you Paste a sprite?
« Reply #7 on: 2009-Aug-20 »
Whoops!!!  :whistle: Going to walk off stage quickly and quietly now!

A real stupid mistake to make - thankyou both for your time and patience.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: How do you Paste a sprite?
« Reply #8 on: 2009-Aug-20 »
Take a look at GRABSPRITE or USEASBMP, please.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: How do you Paste a sprite?
« Reply #9 on: 2009-Aug-20 »
To simply paste an image as a background, so it looks the same on any screen:

Code: GLBasic [Select]
GLOBAL ScreenX,ScreenY
GETSCREENSIZE ScreenX,ScreenY
ALPHAMODE 1.0
LOADSPRITE "image.png", 1
STRETCHSPRITE 1,0,0,ScreenX,ScreenY
USEASBMP
 
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Re: How do you Paste a sprite?
« Reply #10 on: 2009-Aug-20 »
No need to be embarrassed, Gerfy - we've all made silly mistakes from time to time, and it's usually the really obvious problems that leave us scratching our heads wondering what the hell is going wrong! =D
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Hatonastick

  • Guest
Re: How do you Paste a sprite?
« Reply #11 on: 2009-Aug-20 »
Yeah I'll say.  I post such questions all the time. :)