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.

2D All the way! / BackGround!

Author
Message
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 31st Aug 2003 07:41
Heres 1 little question...

If someone was making a top-down 2d shooter, what would be the best most efficient way to have a scrolling background? also state the process if you can.

thx in advance.

Those who Fight with swords get killed by those who don't
Dostej
21
Years of Service
User Offline
Joined: 21st Jan 2003
Location: Switzerland
Posted: 1st Sep 2003 19:17
hm, not sure about. Maybe a tiling engine, if u try to use the background in your game.
Otherwise maybe a sprite and the change the uv-data to do the scrolling. Should be fast.

www.dbpro.ionichost.com
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 1st Sep 2003 21:28
sooo.... Im not sure what your talking about exactly.
Quote: "Otherwise maybe a sprite and the change the uv-data to do the scrolling."
do you mean paste a sprite and just scroll it?

Those who Fight with swords get killed by those who don't
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Sep 2003 04:55
The most common way is to make 32*32 squares that fit together like jigsaw pieces..they are the background images, and can be repeated to make new images like a photofit. First you paste them all down on a second screen to make one full screen. Then you screen copy them to the front screen which should be smaller than the back screen to allow for scrolling. Next you just grab the back screen and move it over by 32 pixels. Now paste a new row of tiles all the way across/ or down depending on the scroll direction. Not the entire screen is updated, just one row, it's quicker. Now you can screen copy the image again, but just 1 or 2 pixels to the left/right/up/or down depending again on the scroll direction. You can keep grabbing the back screen several times before a new row of tiles needs to be added. So what you have is lots of time to do other things, like move sprites etc. This is a common way to make top down scrollers.

Pincho.
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 3rd Sep 2003 01:38
ok Thanks I think i understand .
But I still have some questions.

If i use then method of dividing up the screen by 32x32 sized blocks i end up with a grid 15x20 block sizes (for 640x480 sized screen). Even having a small level, there are going to be alot of small sprites to create. would it be possible to use "strips" since I am only moving in 1 direction? This would cut down on the code (therefore making it easier to manage), and probaly speed up development time(i am still not used to using the 'get image' command).

Those who Fight with swords get killed by those who don't
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 3rd Sep 2003 08:29
create two tests by making flat colour boxes to simulate the code engines


ink rgb(255,255,0),1
box 0,0,31,31
get image 1,0,0,31,31
cls


creates a yellow box 32 pixels and stores it into image media location 1 ready for use in a sprite or whatever.

http://www.lunarpixel.com
It's already tomorrow in Australia
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Sep 2003 11:46
Well you don't actually draw all of the graphics as little squares. You can draw them as pictures that divide by 32. Your pictures could be 64 * 128 * 256...etc. Then you just chop them up into squares. Then you try to re-use the squares in other places. If you use strips then it is hard to re-use the graphics later, and you will soon not have enough memory for all of your huge bitmaps. Although you could use strips if you don't mind having a repeating background.

Pincho.
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 3rd Sep 2003 12:29
its prolly best to keep them within 256 pixel strips for some older cards when testing on many platforms.

http://www.lunarpixel.com
It's already tomorrow in Australia
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Sep 2003 15:41
An alternate method would be to use 1 big background image, and make it into a sprite - to scroll the image you can change the UV data. This would allow any resolution settings because you can scale the sprite to suit the resolution.


Van-B

My cats breath smells of cat food.
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 3rd Sep 2003 19:06
Well I will probaly go with Van's & Dostej's idea of useing 1 big image and changing to uv data. Im not really worried about reusing the images because im going to leave that up to the artist at his own discretion.

Also it sounds a lot easier to manage then squares ( yeah, im Lazy )

thx guys

Those who Fight with swords get killed by those who don't
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 4th Sep 2003 06:23
Sorry guys, but im going to have to bother you again

When you say edit the UV data do you mean use the 'set sprite texture coord' command?

I have been fooling around with it and havent a clue how to use it to scroll. Right now alll i have been able to do is "warp" the texture a bit.

Can you show some example code of editing UV data? that would really help.

Those who Fight with swords get killed by those who don't
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Sep 2003 15:27 Edited at: 4th Sep 2003 15:29
Your on the right track, texture coordinates work on a 0.00-1.00 style scale, so if you set the UV coordinates to 0.0,0.0,0.5,0.5 - you'd get the top left quarter of the image. I can't really make a code snippet for you right now, but I know for sure that it works because I use the same method in my matrix editor for UV mapping the tiles - you select the texture area the selection is shown in a scaled up sprite. All you really need to do is calculate the size of your physical screen in comparison to your background, then that can be your size, and scrolling is a case of changing the start X and Y of the UV. You'd have something like (psuedo code):

Scrollx#=0
Scrolly#=0
Widthx#=screen width()/imagewidth
Widthy#=screen Height()/imageheight
sprite 1,1,0,0
set sprite size 1,0,0,screen width(),screen height()

do

inc scrollx#,mousemovex()/1000.00
inc scrolly#,mousemovey()/1000.00

if scrollx#<0.0 then scrollx#=1.0-widthx#
if scrollx#>(1.0-widthx#) then scrollx#=0.0
if scrolly#<0.0 then scrolly#=1.0-widthy#
if scrolly#>(1.0-widthy#) then scrolly#=0.0

set sprite texture coord 1,scrollx#,scrolly#,scrollx#+widthx#,scrolly#+heighty#
sync
loop


If your still struggling by the weekend, I'll have my PC back and can make a proper example.


Van-B

My cats breath smells of cat food.
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 5th Sep 2003 05:17
Well you code looks good, but "set sprite texture coord 1,scrollx#,scrolly#,scrollx#+widthx#,scrolly#+heighty#" dosent work . The parameters for that command are "Sprite number, Vertex index,UValue,VValue". I think what you where trying to do was input coordinates for the texture.

also, why did you use the mousemove commands?

Those who Fight with swords get killed by those who don't
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 5th Sep 2003 06:52
I can't get this to work either? I've tried sometime ago but never was able to scroll the texture, just wrap or stretch it in some funny way.

CTP
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Sep 2003 15:41
I should get my PC setup tonight so I'll have a look at my code, it does work though, there is a way to specify both sets of UV coords. In fact, I'm sure there's a demo on this website in the tutorials section showing a similar method, maybe that would help in the meantime. Either way I'll try and get a working example to you tonight.

Ohh, and the mousemove commands are good for testing simple bits of code, if it had worked you'd be scrolling the screen with the mouse.


Van-B

Van-B

My cats breath smells of cat food.
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 5th Sep 2003 19:41
I looked at the tutorial and I think i understand it a bit more. HOwever, i won't get a chance to test is until latter in the afternoon (for where i live). I think the main problem with you code is that set sprite texture coord requires the sprite #,vertex,uv,vv. So in order to move a whole pic we need to do four(4) set sprite texture coord. Other wise, its just moveing 1 corner and warping the pic.

Those who Fight with swords get killed by those who don't
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 6th Sep 2003 00:21
that must be what i'm doing wrong then
CTP
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 6th Sep 2003 05:57
YES I DID IT!!!

It came out exactly like i thought... here is some code if you still trying to do it Closetoperfect.(psuedo code)



Those who Fight with swords get killed by those who don't
TheAbomb12
20
Years of Service
User Offline
Joined: 14th Aug 2003
Location: Amist the blue skies...
Posted: 6th Sep 2003 05:59 Edited at: 6th Sep 2003 06:33
Oh yeah, 1 last question i promise...


Altering the Uv data if good (and fast) but it can only repeat it self. What do you suggest i do if i want to change the background midlevel?

Those who Fight with swords get killed by those who don't

Login to post a reply

Server time is: 2024-04-20 06:11:31
Your offset time is: 2024-04-20 06:11:31