GLBasic forum

Main forum => GLBasic - en => Topic started by: Gerfy on 2009-Aug-20

Title: How do you Paste a sprite?
Post by: Gerfy 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.
Title: Re: How do you Paste a sprite?
Post by: Hatonastick 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.
Title: Re: How do you Paste a sprite?
Post by: Gerfy 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)
Title: Re: How do you Paste a sprite?
Post by: Hatonastick 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?
Title: Re: How do you Paste a sprite?
Post by: MrTAToad 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.
Title: Re: How do you Paste a sprite?
Post by: Gerfy 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.
Title: Re: How do you Paste a sprite?
Post by: MrTAToad on 2009-Aug-20
Sure your actually calling the function before trying to draw everything ?
Title: Re: How do you Paste a sprite?
Post by: Gerfy 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.
Title: Re: How do you Paste a sprite?
Post by: Kitty Hello on 2009-Aug-20
Take a look at GRABSPRITE or USEASBMP, please.
Title: Re: How do you Paste a sprite?
Post by: Hemlos 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
Title: Re: How do you Paste a sprite?
Post by: PeeJay 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
Title: Re: How do you Paste a sprite?
Post by: Hatonastick on 2009-Aug-20
Yeah I'll say.  I post such questions all the time. :)