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.

Author
Message
Dragon Tycoon
20
Years of Service
User Offline
Joined: 3rd Feb 2004
Location:
Posted: 9th Nov 2004 05:49
Hey guys. Sorry that this question is so very noobish - I almost feel embarassed asking it - but how exactly do you position sprites and use them and all that jazz? I've been off programming DarkBasic for a while (doing VB for school) and I never figured it out in the first place, so I'm a little - scratch that, very - lost. Could someone please show me some code of it and explain it? Just some random thing int he center of the screen, the far right, far left, yadda yadda yadda.

Thanks for coping with my ignorance, guys.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 9th Nov 2004 06:09 Edited at: 9th Nov 2004 06:11
A useful way of thinking about sprites is that you have to do them every loop, like printing and all other 2D commands. It's not actually strictly true but it means you can understand them.

The main sprite command is:

sprite

This means - stamp an image on the screen. You tell it the coordinates and the image to use, and give it a number just like you give an object a number.

So this will display a sprite at different coordinates:

load image "MyImage.bmp", 1

sync rate 60
sync on
do

`Make a sprite (Sprite 1) at random X & Y coordinates with image 1
sprite 1, rnd(600), rnd(500),1

sync
loop


Sprites have loads of cool features that images don't such as rotate and fade (set sprite alpha).

Here's some code to rotate a sprite:


load image "MyImage.bmp", 1

sync rate 60
sync on
do

`Make a sprite
sprite 1, 200, 200, 1
`Rotate it
rotate sprite 1, a

a = wrapvalue(a + 1)

sync
loop


Remember to offset the sprite to get it to rotate around it's center. The command to do this is:

offset sprite Sprite Number, OriginX, OriginY

If you want to set the origin of a sprite to the centre then make the OriginX value half the width and the OriginY value half the height.
---------------------

Some people say that sprites are just like 2D objects but this isn't really right because you can very easily change what picture each sprite is showing and because there are no 'position sprite' commmands.
Dragon Tycoon
20
Years of Service
User Offline
Joined: 3rd Feb 2004
Location:
Posted: 10th Nov 2004 03:42
Thanks! I've been looking at examples of code, but it was just way over my head until I actually knew what I was doing. Hopefully this will be the last of my incredibly nooby questions.

Thanks again.
VietDao
19
Years of Service
User Offline
Joined: 30th Oct 2004
Location: Earth, Lovely Earth
Posted: 13th Nov 2004 22:51 Edited at: 13th Nov 2004 22:55
Hi,
Sprite commands are oh-so-easy to learn. I think I can help you understand it exactly.
Sprite is something that lies above everything you draw on the screen. It's like an image stamped to the screen as Chris K had told you. So when you PRINT a text on the screen and position a sprite right on it. You won't see the word, just see the sprite, if it is big enough to cover all the word. Or you will see parts of the word if the sprite is not big enough. Do you understand?
Sprite is grabbed exactly form an image.
Image is something like a bitmap, and uses memmory of your computer to store it. It will be freed after the programme finished. The image is a part of a bitmap or a whole bitmap. Is it any clearer now?
1.So to have a sprite, the first thing is to have an image and connect the image to the sprite.
To LOAD an image from a bitmap file, simply use the command
LOAD IMAGE Filename, ImageNumber
You will find this command in the MANUAL coming along with the DarBasic programme you purchased, or in the HELP section in DarkBasic programme.
Or you can grab a part of an image from a bitmap, but first, you must load a bitmap (too clear as if there is no bitmap, where can you grab an image from?). Use the command LOAD BITMAP Filename, BitmapNumber
Before you can grab an image, you must set the current bitmap to the one you want your image grab. Use SET CURRENT BITMAP BitmapNumber command to do this. The screen holds the BitmapNumber of 0. Every other bitmaps use memory to retain, you cannot see them. When SET CURRENT BITMAP, all operation will take place on the bitmap you set current. Like if you SET CURRENT BITMAP 1, and PRINT "A", the letter A will be printed on bitmap number 1. Understand?
Use GET IAMGE ImageNumber, Left, Top, Right, Bottom to grab from the current bitmap.
The screen consists of dots called pixels, you can grab the image by pointing out the correct frontier on the bitmap. The image must be a rectangle. The first pixel on the screen has an X coordinate 0 and Y coordinate 0.
If the pixels on the scren is like this:
00000000000000000000000
00011111111111111111000
00011111111111111111000
00011111111111111111000
00011111111111111111000
00011111111111111111000
00011111111111111111000
00000000000000000000000
Number 1 represents the part will be grabbed from the bitmap.
To grab the image like that, type in:
GET IMAGE 1, 4, 1, 19, 7
After grabbing an image, you can return to the screen, and do all the operation on it by SET CURRENT BITMAP 0
2. To position a sprite, use:
SPRITE SpriteNumber, XPos, YPos, ImageNumber
This will create a sprite has a number ID and links to a certain image, and place it on the screen at X, Y. The X and Y is just like what I show you above, X refers to the pixels counted from the left of the screen to the left of the Sprite, Y refers to the pixels counted from the top of the screen to the top of the Sprite.
To move a Sprite, just specify another value of XPos and YPos.
To set the sprite top-left assign XPos and YPos to 0 as the first pixel of the screen has X = 0, and Y = 0.
To set it top-right, set XPos to the width of your screen subtract 1 and subtract the width of the sprite (you will see how to get the width of the srpite below) as the fisrt pixel has the X = 0, and set YPos to 0. To get the width of your screen, use SCREEN WIDTH() command.
To set it top-center, set XPos to Int(the width of your screen - the width of the sprite) / 2), and set Ypos = 0. To get the width of your sprite, use SPRITE WIDTH(SpriteNumber) command. INT() command will take the part before the dot in the number like 0.5. INT(0.5) will return 0. Since XPos and YPos cannot be 0.3 or 0.5, or something like that, you must do it.
To set it center of the screen, set XPos to Int(the width of your screen - the width of the sprite) / 2), and set Ypos = Int(the height of your screen - the height of the sprite) / 2). To get the height of your sprite, use SPRITE HEIGHT(SpriteNumber) command.
I hope this will help you understand what sprite is and how to place them. Deleting the image the sprite links to will make the sprite disapear. You can delete the bitmap the image links to without losing the image. Use
DELETE IMAGE ImageNumber
DELETE SRITE SpriteNumber
DELETE BITMAP BitmapNumber
You should SET SPRITE SpriteNumber, 1, 1 or your sprite will appear on the BLUE screen. Refer to the MANUAL for help.
********************
You will find loads of Sprite commands in the MANUAL, read the instruction carefully and you will be able to use every of them. There may be some mispelled words, just forgive me. This text is too long...
Hope my long post help,
See you,
Bye bye,

Login to post a reply

Server time is: 2024-09-23 04:26:40
Your offset time is: 2024-09-23 04:26:40