Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / sprite help

Author
Message
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 23rd Dec 2006 20:53
okay i have a few questions about sprites cause ime a bit confused at themo:

just to clarify whith sprites you need an image for them to exist right?:
it says in the help SPRITE Sprite Number, XPos, YPos, IMAGE NUMBER

well if so and theres no way of making a sprite out of a box or whatver is it possible for you to change the colour of a sprite.

For instance i want to make a box whith a black outline that you have the choice to change the colour of the middle to anything, but still keep the black outline?. or is the only way to load several different images and depending on the choice put different sprites up. thanks

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 24th Dec 2006 01:30
ah i see i think there is a way to do it its whith the paste image commands or somthing, could somone explain how to do both of these thing please.thanks.

oh and incase you dont understand what i am asking it was:
1.can you change the colour of a sprite or a box depending on a variable.
2.can you make a sprite out of the "box,1,1,1,1" command. thanks

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Barbarian
17
Years of Service
User Offline
Joined: 11th Dec 2006
Location:
Posted: 24th Dec 2006 01:36 Edited at: 24th Dec 2006 13:21
isn't a box a 3d image and a sprite a 2d image?

EDIT: ohhh, my bad, i thought you ment make object box
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 24th Dec 2006 01:46
no i dont mean make object box, i meant box [], its under 2d commands in the help file.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Dec 2006 02:42
You are correct, what a sprite looks like is purely down to the image.

Just use different image numbers in the Sprite command as you suggested.

Or...

If the image is simple enough to create with DB's 2D drawing commands, create a second bitmap (number 1) with Create Bitmap, draw the box on it in the required colour and use Get Image to grab it for the sprite.

After you have grabbed it, use Set Current Bitmap 0 to switch back to the main screen and delete Bitmap 1 (or leave it there and switch between them with the Set Current Bitmap command).

TDK_Man

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 24th Dec 2006 16:33 Edited at: 24th Dec 2006 16:50
okay cool, i understand the basic way i will have to set up my code i think.

but i have no idea about coding it if you could talk me through it, or point out a tutorial that would be great. thanks.

edit: i meant coding err, to draw a box or somthing whith 2d commands and making into a sprite with the get image commands. lol i thought i better point that out incase i was a bit vague.

i am experementing at the mo but nothing conclusive found. thanks steve

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 24th Dec 2006 19:44
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Dec 2006 21:27
Try this...



The sprite changes colour when it hits the edges of the screen.

The procedure NewSpriteImage changes the colour, so just call it when you click on the mouse instead of when the sprite reaches the edge of the screen.

TDK_Man

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 24th Dec 2006 21:43 Edited at: 24th Dec 2006 22:07
okay thnks guys, but tdk man when i run your code i just get a black screen, but it is okay ill use your code and ants code and see what i come up whith, thank you, i think if i just read through it a bit and look up some commands etc. i will get it.

oh sorry i forgot to say ime working in pro, thanks for the extra lines, but still the black screen.

thanks steve


i dont understand the cls command, it just clears the screen whith whatever colour you put in, i think. but it doesnt seem to stay that way so how does, get image, work. does it grab the image in the split second the screen changes colour?

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 24th Dec 2006 22:25
Just had a look at TDK's code he just forgot to set the current bitmap to 0. I have ammended the code and it now works! Hope you don't mind TDK.



TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Dec 2006 22:30
Not at all - sorry my fault for posting DBC code without testing it in Pro first. (Was testing out my new IDE for DBC at the time).

Yes, DBP needs an extra Set Current Bitmap which you don¡t need if you run it in DBC.

TDK_Man

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 24th Dec 2006 23:08 Edited at: 24th Dec 2006 23:31
oh aswell as the cls command, i am having trouble whith the screen i really dont know how it works, i am having trouble whith positioning the sprite for instance if i wanted it to be on the left and in the middle of the screen would i put -800,0 (based on 800x600 res) or somthing else?. woops, silly me 800,is the right and 600, is the top i see now.

but why is there a image now in the top left corner of the screen and does it have to be there?

and the get image command doesnt seem to work all the time it only seems to work whith certain numbers?

oh and i know this is a lot of questions but might aswell get em all out in one go aye.

oh yes, i have to ways of doing this now tdks and ants but is one of them better?

and i dont seem to be able to change the backround colour i have to use the cls command in yours tdk?

thanks for all help guys.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Dec 2006 00:32
My code was only to demonstrate how to change the colour of the sprite - nothing else.

If you create sprite 1 and image 1, then grabbing a new image 1 will automatically change the sprite it's attached to the next time you use the Sprite command.

If you are getting an image in the top left corner it sounds like somewhere in your code you need a Set Current Bitmap 1 - because the image is not being drawn on the hidden screen (bitmap 1).

Below is the code from above altered and ran in DBPro with no problems:



The top left corner of the screen is X=0/Y=0 and the bottom right corner X=799/Y=599 when in 800x600 screen mode.

When you say 'background colour', do you mean around the edges of the box? If so, you change the CLS RGB(R,B,G) line. The box is drawn using the next INK line colour, but one pixel smaller than the sprite's size so that when you grab the sprite image it also get's the one pixel border in the CLS colour.

When you create another image you simply alter the INK's RGB values.

You should check out some of the tutorials on the Newcomers board - I'm sure you'll find most if not all of the answers to your questions there...

TDK_Man

Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 25th Dec 2006 00:51
When you create an image using GET IMAGE it saves a portion of the screen indicated by your image number.

Get image Imagenumber,0,0,imagesizex,imagesizey

Basically this command tells the computer to grab an image using the screen x co-ordinates of 0 to imagesizex and the y co-ordintates 0 to imagesizey

Obviously you would need to declare the variables beforehand, by the way they are integer(Whole numbers), the image stored would be black as we did not change the colour of the screen before calling the GET IMAGE command.

imagenumber=1
imagesizex=20
imagesizey=20

So now the computer will store the image in memory using your image number as a reference, but the image would still be there if we had chosen another colour to clear the screen with before calling the GET IMAGE command.

Whenever we use the GET IMAGE command, to create a sprite, we need to clear the screen except in this case, the screen was on the default colour of black so it doesn't need to be done.

CLS 0 or CLS RGB(0,0,0) will clear the screen black
CLS -1 or CLS RGB(255,255,255) will clear the screen white

or choose whatever colour you want using the RGB command

if we create a sprite we end up with a blue screen. To avoid this we must use the command

COLOR BACKDROP chosen colour

So now create a sprite using our image

Sprite spritenumber,screen position x,screen position y,imagenumber

Once again if you use the above command you would need to declare the variables

spritenumber=1
screen position x=300
screen position y=200

imagenumber has already been declared above.

I must point out that using our black image for a sprite is not the best example because the sprite command normally ignores the black sections of a sprite and pastes the image not showing the black sections, unless we call another command

SET SPRITE spritenumber,backsave,transparency

Have included the code, hope it helps !!!!

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 26th Dec 2006 15:38
okay wooooo, i get it now and i feel so proud. =)

but there is one problem and i cant seem to work it out i am pretty sure i am doing everything right and yet i cant get the sprite to move?

i even tried doing the speedy=speedy+1 way. thanks



no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 26th Dec 2006 16:50
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 26th Dec 2006 17:23
cool thanks. i am gratefull. but i am not sure why that should make any difference, it makes the sprite then in the main loop moves it, now it, well from what i understand makes the sprite overand over again? because its in the main loop?.

thanks for the help though. cheers steve.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 26th Dec 2006 18:33 Edited at: 26th Dec 2006 18:37
This code might help you out also

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 26th Dec 2006 19:04
cool thanks.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 26th Dec 2006 19:54 Edited at: 26th Dec 2006 19:55
i think i am meant to post here not start a new thread so here goes.

i also need help making a pong game, heres what i have so far

i think its all allright, but i need help whith the ball moving and bouncing off the bats and walls, i have read the tutorial but i just cant make sense of it and its 3d so it might work different, and i have looked at other peoples code but i cant get it. thanks steve

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 27th Dec 2006 00:06
This is just the basics, need some work

steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 27th Dec 2006 17:51 Edited at: 27th Dec 2006 18:35
.........err, i think i have done it

is that the right way to do it, or is there a proper way becasue i thought you would have to use spriteangle or somthing a bit more complicated?

okay i dont think it is right, it needs somthing else ime not sure how to do it though, it needs to bounce of the bat at different angles, depending on bat movement.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 27th Dec 2006 20:56 Edited at: 27th Dec 2006 21:08
This might give you some ideas, the ball will go behind the bat now and needs some more collision work amongst other things.


steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 28th Dec 2006 20:37
isnt there a way to make the ball bounce using the abs command because i am finding the ball slows down when i boince it off walls and stuff.?

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 1st Jan 2007 18:40 Edited at: 2nd Jan 2007 17:34
okay this is my code, whith help obviously.
Ii just cant get it, the game is not very good in my opinion it bounces the same everytime nearly, and when it bounces of the bats it doesnt matter at what angle it hits them its always the same bounce angle can somone help pls.

or is my code right and its just me?



no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
steve c
20
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 3rd Jan 2007 21:34
oh yes and there is a command dist=sqrt i dont know it but i know it gets the distance and i was wondering if it worked for sprites?. thanks, steve.

no current projects starting db from scratch, so i can program stuff well, noob tutorials ime coming.

despite what it sais to the left joined 5 december 03
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Jan 2007 23:38
Not a flame - just a few tips to help you on your way...

Your code could be made a fair bit easier to read - so others can follow it better. For example:



is easier to follow if you use:



CLS rgb(0,0,0)

can be changed to:

CLS 0

because the RGB() function involves a calculation which in this case isn't needed.


Indent!

Indent all your code if you intend to post on the forums. It takes time for people to study your code and find out where you can improve things. Making your code easier to follow improves the chances of getting a response.

Subroutines and functions when not indented tend to blend into the code and makes it look more complicated than it actually is. This may put people off helping.

I pasted your code into my IDE and told it to auto-indent it. Take a look at the difference it makes...



Collision:

Rather than check for every specific sprite collision, try just checking only the ball with 0 as the second sprite number. For example, if the ball is sprite 1 then the command:

BallHit = Sprite Collision(1,0)

...will return the number of any other sprite the ball collides with. You therefore only have to do one collision check and decide what to do next based on the sprite number returned.

Set Current Bitmap:

This is only required if the current bitmap is not the one you want to write to.

If you use Create Bitmap 1,320,200 then that command automatically sets the current bitmap to 1, You therefore only need to use Set Current Bitmap 0 when you want to switch from bitmap 1 (the hidden screen) to bitmap 0 (the screen the user sees).

At which point you should use Delete Bitmap 1 if you aren't going to use it again.

Note: If you delete a bitmap, it doesn't delete any images you have previously grabbed from it.

TDK_Man

Login to post a reply

Server time is: 2024-09-25 15:23:20
Your offset time is: 2024-09-25 15:23:20