forums

TNT Basic Forums > Programming Q&A
Map scrolling issue
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-01-2003 20:56

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

I am new to TNT, i have only done it for 2 days (if that) and am trying to make a scrolling map. I need to keep a really high FPS because I will be adding in lots of sprites later so I am trying only to draw the map right outside of the viewport. This is the error I keep getting:
*** Runtime exception caught ***
Line# : 49
Code : set viewport offset 1,mapX,mapY
Error : The viewport can only be specified so that all of it lies inside its canvas.

and this is my code:

global int displayX=640
global int displayY=480

global int maxx=map width * map tile width - 300
global int maxy=map height * map tile height - 300

hide mouse
fade down
graphics mode displayX,displayY
vbl sync off

set framerate max

load map 0
load images 128

open canvas 1,displayX+map tile width,displayY+map tile height

open map viewport 1,0,0,0 to displayX,displayY

'draw the scrolled area
canvas 1

draw frame
fade up

int done=false
int mapX=0
int mapY=0
int charX=0
int charY=0
while not done
canvas 1
if left then mapX=mapX-2
if right then mapX=mapX+2
if up then mapY=mapY-2
if down then mapY=mapY+2

if mapX<0 then mapX=0
if mapY<0 then mapY=0
if mapX>maxx then mapX=maxx
if mapY>maxy then mapY=maxy

if Pressed(12) and done=false
done=true

end if

set viewport offset 1,mapX,mapY
canvas 1
draw map section mapX/128,mapY/128 to mapX/128+displayX,mapX/128+displayY,0 to 0,0

draw frame
wend

fade down
end

does anyone know what is wrong with it?

06-01-2003 21:42

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

The answer is simple. You cannot place the viewport out of the map.

06-01-2003 22:32

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

its not out of map, or at least I don't think it is. The map is pretty big, i would be surprised if it was, it is about 50x50 tiles, each 128x128 pixels.

06-02-2003 22:06

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

So if you're not placing the viewport out of the map, what do you mean by:
> I am trying only to draw the map right outside of the viewport.


Doesn't it mean exactly the same thing??????

06-03-2003 00:52

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

What I meant was, I guess it's not clear, that I only want to draw the map where the user is viewing and immediatly around it (1 tile wider)

06-03-2003 14:36

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

don't try to do it that way. draw the whole map.

06-03-2003 21:32

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

What you have to do is open a small viewport.

06-04-2003 01:33

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

shivers,
the command "open MAP viewport" automatically creates a canvas slightly larger than the map and will automatically draw in the needed portions of the map. All you have to do is set the viewport offset and it will draw the correct area of the map and keep track of all the sprites. You should check the TNT help file, it's really...helpful.

06-04-2003 01:43

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Sorry shivers, I didn't answer your question, did I? Your problem is with the globals maxx and maxy. Declaring them before the map is loaded means that they are both set at -300, because map width, map tile width, map height, and map tile height are all 0. (There is no map open!)
Then, because of these lines

>|if mapX>maxx then mapX=maxx
>if mapY>maxy then mapY=maxy

mapX and map Y, which are greater than -300, are set to -300, and

set viewport offset 1,mapX,mapY

sets the viewport to -300,-300


Hope this helps

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.