forums

TNT Basic Forums > Programming Q&A
Background
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-18-2005 19:53

Posted by:
Ian

Location:
canada

Find more posts by Ian

I'm making a platformer, but im having trouble with background. i'm not entirely sure how to create a scrolling background behind a map. i've tried, but creating "blank" tiles where i want the background gives me some interesting glitches, and the picturem (which appears in front of everything) flashes everytime the map scrolls. any help is greatly appreciated!

Thanks,
Ian

08-18-2005 21:29

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Hi again Ian...

Do you actually get 'odd shaped' tiles? Which way did you go in the end and what sort of glitches are you getting?

Are you showing the foreground in a separate viewport or just pasting it over the top of the map? If it needs to have transparent areas, try making the image a sprite and see if this works. If not, try opening a new viewport and displaying it alongside the map.

Well give these sort of half arsed ideas a go, and let me know how things go. If you can be a bit more specific with the tiles issue I'll see what I can do. If you want to mail me a copy of the source (I'd need the graphics also, so can't really post the code here) I'd be more than willing to have a hack at it, but it's up to you...

Good luck

Danny (nods)

08-27-2005 23:43

Posted by:
Ian

Location:
canada

Find more posts by Ian

i fixed the odd-shaped tiles problem by using a sprite. my problem now is getting a background behind the map, like you would find in any platformer like, say, mario brothers or sonic. ex. mountains and sky in the background that move slightly left as you go right and vise versa.

also, its my understanding that only one canvas can be open at a time. this is correct, yes? and layers... i dont quite get layers. as far as i know, they only exist in the map editor. i havent been able to do anything with them.

thanks,
ian

08-28-2005 01:00

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

OK, canvas thing first. You can have as many canvases open as memory allows, a canvas is just where you are going to draw the next graphic. You can only have one 'active' canvas, as that is where the graphics are sent. It's a picture in memory somewhere, you set the active one and all graphic ops are sent to that 'picture'.

Layers next. For what you are trying to do, layers wont help (unless the picture you are trying to display behind the map is made up from tiles, ie another map). Layers (at the moment) give you the oppertunity to save more than one map definition to the one map resource. This whole thing needs to be sorted out, it doesn't mean what it says so is irrelevant for your situation, it doesn't do transparency.

I will upload a tutorial and example for this, but what you need to do is replicate the map as a 2D array of sprite images. Create the map as normal, and make each of your tiles a separate sprite in a separate bank. Before you start the level, go through the map row by row and column by column and load the tile reference into the corresponding array element. You then ignore the map routines completely! You find out the origin (x and y coordinates of the the top left corner) and draw the background image using standard calls. You then need to go through your array to find the sprites that would be visible at the current origin and draw them on screen. You only use the map as a reference, not as a structure passed to the map calls.

I hope you get the idea of this, I have been looking at things to explain further, and this will be the next one, so give this a go if you get what I mean, otherwise wait for a day or so (time permitting!) and I'll post a full example and description in this thread).

There is a parallax scroll routine in the directory if you want to take a closer look (I haven't checked it out, but I trust the author!), so if you can't wait it's gonna be worth a look!

Have fun and try to get your head around the above ideas...

Danny (nods)

08-28-2005 08:32

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Scrolling the background...

Doh! Forgot to mention the actual scrolly thing... You'd just open a canvas the size of your backdrop and a normal viewport (not a map viewport). When you scroll your map by moving the sprites, you'd scroll the viewport the opposite way by a smaller amount (with 'set viewport offset'). Just remember to make the backdrop the correct size (or better still, use a map) and check for the viewport being 'in bounds'. If you used a map you would obviously need to open a map viewport, not a normal one as mentioned above.

Alternative: If you want / need more than two layers of scrolling you could try opening a canvas the size of the complete map(s). Draw the map into that canvas in its entirety then copy the full image to a spare ID with transparency. You could then scroll as many images as you liked (processor speed allowing!) by pasting the images ('paste image x, y, ID') at the correct offsets. You would use the map data as a reference for collisions and so on, but otherwise ignore it. Just a thought...

Danny (nods)

08-28-2005 22:44

Posted by:
Ian

Location:
canada

Find more posts by Ian

hm... it seems this is going to become a bit complicated... you would think that there would be an easier solution. thanks a ton for your help. im definately looking into this sprite map thing.

one question though. have you looked at "bang on!"? how does it pull off its background? ive looked at its code and everything and done exactly what they did buit it doesnt work in my game. bang on is pretty much doing what im trying to do. is the difference that it doesnt scroll? i dont know.

thanks again
ian

08-29-2005 07:22

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

It's not as complicated as all that. Rather than looking at 'Bang On!', try these examples from Mark & John. There are four code snippets here which demonstrate the whole viewport thing in detail. The 'Outdoor' example needs some modification to work under OSX (as it uses input calls that don't work at the moment!), but you can get the basics from the other three.
Yes, 'Bang On!' doesn't scroll and that is the difference, but you will see what I mean when you've checked out the link above. If you think of a 'canvas' as an image in an art package, and a 'viewport' as the application's window. You use the scroll bars to move the 'view' around the image (note 'scroll' bars). To scroll in TNT you just need to change where the top left corner of the 'window' is programatically (with 'set viewport offset'). It's a doddle really!
If you are using sprites to show tiles, you've already done the hard bit, so keep plugging away, and keep an eye on the forums. I'll post a full example soon.

Have fun!

Danny (nods)

08-30-2005 01:53

Posted by:
Ian

Location:
canada

Find more posts by Ian

the sprite tiling thing slows my frame rate down to a whopping 2. maybe im doing it wrong

basically, you draw the tile graphic in another canvas, then copy sections of it as sprites to canvas 0 where the corisponding tile is. so basically its a sprite for every tile on screen. thats 300 sprites in my case, not including the normal sprites i use in my game. im guessing thats whats slowing it down.

also, i understand viewports and scrolling and all that. thats not a problem.

alpha mask tiles reeeeeeaaaaaallly should be included in the map editor. it seems odd that it isn't.

thanks for the help
ian

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.