forums

TNT Basic Forums > Programming Q&A
Map Viewport Offset Not Working
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-09-2006 17:33

Posted by:
Farmer

Location:
Somewhere in space...

Find more posts by Farmer

I made a map that is pretty huge: 48x50 tiles. I wanted the players to start in the bottom left hand corner, so I made code relatively similar to this:

quote:
Load Map "My Map"
Map Viewport 1, 0,0 to 800,500
Set Viewport Offset 1, 0,2000
...(other code)...
My problem is that the image it shows here is the one that should appear when I scroll to (0,500), but all the sprites are in the right place. In fact, when I move to scroll up and/or right, the part of the map that I couldn't see before appears correctly, and when I scroll back to the lower left hand corner, the map tiles are, again, correct. It's just the initial scroll, then, that seems to be the problem.

If it would be helpful, I could include some screenshots. I'm thinking this may be a problem with my huge maps, but I would like to think that it wasn't. I like my map the way it is. :)

Thank you for your help!

12-09-2006 19:37

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

could you provide more code? it's very hard to tell from 3 lines

12-09-2006 19:40

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

i suspect "Set Viewport Offset 1, 0,2000" is not the only Set Viewport Offset command in your code, since it's possible to scroll.

Maybe you have some kind of

Set Viewport Offset 1, scroll_x, scroll_y

command that cancels the effect of the first one?

12-11-2006 06:11

Posted by:
Farmer

Location:
Somewhere in space...

Find more posts by Farmer

You are correct.

I did have scrolling later on in my original code, but I created a project file that has nothing more than my huge map, its tile image (under graphics), and the following code, verbatim:

quote:
Window Mode 800,600
Load Map "World 1"
Open Map Viewport 1,0, 0,0 to 800,500
Set Viewport Offset 1,0,2000
Draw Frame
Wait Mouse Click
This produces the same effect, showing me a part of the map that it shouldn't. The part that it shows me should be at (0,900) on the map. Interestingly, when I change the values to (0,900) so that I should see the part that it was showing me before at (0,2000), it worked. The viewport showed the same thing both times. Perhaps there is a maximum offset value for "Set Viewport Offset"? It confuses my head...

Thank you for heading my cry.

12-11-2006 07:54

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Obvious question...

How big is the map?

Danny (nods)

12-11-2006 08:04

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

OK, Ok... it's early...

Right, seen the size (need coffee!). Are you tiles 40 square by any chance? If so this is your problem. You are setting the offset to be outside the map and TNT is wrapping the values. The bottom of the map is calculated as height in tiles, multiplied by tile height minus the height of the view port.

Try setting the y value to 1500 (2000 - 500 for the viewport) and see if this works...

Danny (nods)

12-11-2006 18:57

Posted by:
Farmer

Location:
Somewhere in space...

Find more posts by Farmer

Little off...

The tiles are 50 square, so my map is 2500 pixels tall. Minus 500 equals: 2000.

Maybe you could try making a similar map and see if you have the same problem. If not, it might be my graphics or my computer or something else.

12-11-2006 19:23

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

DOH!

Nice idea though ;)

Well that's truly bizarre then. I can't see another reason why it would go pear shaped until you scroll, then go back to normal. If you want to mail me a copy of your project I'll take a look at it for you. To resolve it I'd need to use the same map and tiles (to eliminate an error in the resources and pin it down to TNT). If you're happy with that I'll see what I can do...

Otherwise (serious cop out option) you could try scrolling the screen and scrolling it back before you do a 'draw frame' call. I'm not saying it will work, and it's not the best solution to a tricky problem, but it's worth a go to get you out of a spot.

Danny (nods)

12-12-2006 04:47

Posted by:
Farmer

Location:
Somewhere in space...

Find more posts by Farmer

Thank you for the offer.

I'm emailing...

I did try that back-scrolling thing before. This updated code doesn't make any difference:

quote:
Window Mode 800,600
Load Map "World 1"
Open Map Viewport 1,0, 0,0 to 800,500
Set Viewport Offset 1,0,1450
Set Viewport Offset 1,0,2000
Draw Frame
Wait Mouse Click
... but this does:
quote:
Window Mode 800,600
Load Map "World 1"
Open Map Viewport 1,0, 0,0 to 800,500
Set Viewport Offset 1,0,1450
Draw Frame
Set Viewport Offset 1,0,2000
Draw Frame
Wait Mouse Click
I could cover up the screen with a black sprite during this frame drawing or something, but that would be less than desirable and it is not a reliable solution.

I hope looking at the project helps. Thank you. :)

12-12-2006 21:16

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

OK, took a look at Farmer's code...

There's nothing wrong with it, should work fine but it doesn't, and I've no idea why. You get the same result if put the viewport in the top right corner as well, I'll need to keep adjusting the values until I get a proper display first time round and work from there.

Solved it though, but had to cheat. I opened a canvas and drew the whole map into it, then opened a viewport onto it and scrolled that. This works, but the map viewport call doesn't. I'll log it and look into it later.

Anyway, looks like it could well be a bug, but I still have a copy of the project and will try a few more things (changing the graphics, map tiles and looking into the data) before I tackle the source, if I find anything out I'll post it here.

Danny (nods)

12-18-2006 04:38

Posted by:
Farmer

Location:
Somewhere in space...

Find more posts by Farmer

Fixed! Many thanks...

I put a procedure in my game called openMapViewport(int newCanvas, int x1,int y1,int x2,int y2) that basically takes the variables, opens a viewport of the correct dimensions that leads to a canvas the size of the current map with the current map drawn onto it. Pretty much what you said, Danny, only in a procedure with variables.

Aanywaay, just so y'all know 'tis fixed. I look forward to being able to use Open Map Viewport again.

09-14-2009 01:50

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

Could you please post your procedure code? I'm having a similar problem and the way I just tried to solve it makes a blue screen fade up and then crash tnt.

Greatly appreciated

09-15-2009 03:26

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

hey destro - could you post your code?

I used a viewport in DinkyDungeon without any problems - maybe I can help.

cheers

barry

09-20-2009 23:59

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

Thanks for the interest! Dinky Dungeon is great by the way, I got it to see how your viewports were working and ended up playing it for a few good hours.
The bulk is the controls... actually there's not much besides that. The viewport works, but the map duplicates itself as you scroll around it, combining where you are with where you're going.

graphics mode hardware 800,600
hide mouse
load images 128
load sounds 128
load map 128

open canvas 1, 140*16, 140*16

open map viewport 1,0,0,0 to 800,600

global float width=800, height=600
global float yposship= 150, xposship=150
global float shippic=0
global float rotateship=0
global float player=0
global float playerspeed=0, straferspeed=0
global float playerxdir, playerydir
global float playerspeedmono=0, straferspeedmono=0
global float playerxdirstf, playerydirstf
global int astmode=1
global float thrust=0
global float xvelocity=0
global float yvelocity=0

global float xmap=0
global float ymap=0

draw frame
while not mouse button 'MAIN LOOP

xmap = xposship-width/2
ymap = yposship-height/2
if xmap<0 then xmap=0
if ymap<0 then ymap=0
if xmap>map width()*16-800 then xmap=map width()*16-800
if ymap>map height()*16-600 then ymap=map height()*16-600

sprite player, xposship-xmap, yposship-ymap,001
set sprite rotation player, rotateship
set viewport offset 1,xmap,ymap

'FLIGHT CONTROLS

if astmode = 1 'If using MONO-THRUSTER flightmode (navigate using one thruster at a time through the vacuum)
if pressed (55) 'If pressing the strafe button

playerspeedmono = playerspeed
straferspeedmono = straferspeed

xvelocity=xvelocity+cos(rotateship)*thrust
yvelocity=yvelocity+sin(rotateship)*thrust
xposship=xposship+xvelocity-(playerxdir*-playerspeedmono)+(playerxdirstf*straferspeedmono)
yposship=yposship+yvelocity+(playerydir*playerspeedmono)+(playerydirstf*straferspeedmono)

if up and thrust< 0.0225
thrust=thrust+0.0475
play sound 6,100,155,1
else if down and thrust> -0.0225
thrust=thrust-0.0475
play sound 7,0,155,1
else
thrust = 0
end if

if pressed (56) 'MONO Strafing overrides
if right
rotateship=rotateship+4.5
else if left
rotateship=rotateship-4.5
end if
end if

else 'If NOT pressing the strafe button in MONO-flight mode

playerspeedmono = playerspeed
straferspeedmono = straferspeed

xvelocity=xvelocity-sin(rotateship)*thrust
yvelocity=yvelocity+cos(rotateship)*thrust
xposship=xposship+xvelocity-(playerxdir*-playerspeedmono)+(playerxdirstf*straferspeedmono)
yposship=yposship+yvelocity+(playerydir*playerspeedmono)+(playerydirstf*straferspeedmono)

if up
thrust = 0.035
play sound 1,50,75,1
if playerspeed > 0 then playerspeed = playerspeed-0.055
if playerspeed < 0 then playerspeed = playerspeed+0.055
if straferspeed > 0 then straferspeed = straferspeed-0.055
if straferspeed < 0 then straferspeed = straferspeed+0.055
else if down
play sound 0,50,45,1
if xvelocity > 0 then xvelocity = xvelocity-0.055
if xvelocity < 0 then xvelocity = xvelocity+0.055
if yvelocity > 0 then yvelocity = yvelocity-0.055
if yvelocity < 0 then yvelocity = yvelocity+0.055
if playerspeed > 0 then playerspeed = playerspeed-0.055
if playerspeed < 0 then playerspeed = playerspeed+0.055
if straferspeed > 0 then straferspeed = straferspeed-0.055
if straferspeed < 0 then straferspeed = straferspeed+0.055
else
thrust = 0
end if
if pressed (56) 'MONO Speed and brake override
if up
thrust=thrust+0.075
play sound 5,50,175,1
else if down
thrust=thrust-0.015
play sound 4,50,95,1
else if left
rotateship=rotateship-4.5
else if right
rotateship=rotateship+4.5
end if
end if
end if


else 'If using MULTI-THRUSTER flightmode (all thrusters work together to simulate atmosphere)
if pressed (55) 'If pressing the strafe button

yposship= yposship-(playerydirstf*-straferspeed)+(playerydir*playerspeed)+yvelocity 'player's y position = current y position + (current y direction*strafing speed + last y direction faced before pressing strafe button*speed before pressing strafe button) + mono-flightmode speed and direction (+/-) on y axis
xposship= xposship+(playerxdirstf*straferspeed)+(playerxdir*playerspeed)+xvelocity 'player's x position = current x position + (current x direction*strafing speed + last x direction faced before pressing strafe button*speed before pressing strafe button) + mono-flightmode speed and direction (+/-) on x axis

if straferspeed<= 5.5 'If moving in a strafe within speed limit, use these calculations to determine ship direction.
playerxdirstf= Cos(rotateship)
playerydirstf= sin(rotateship)
else if straferspeed>= -5.5
playerxdirstf= Cos(rotateship)
playerydirstf= sin(rotateship)
end if

if xvelocity>0 then xvelocity=xvelocity-0.08 'decays mono flight speed in both directions until 0
if xvelocity<0 then xvelocity=xvelocity+0.08
if yvelocity>0 then yvelocity=yvelocity-0.08
if yvelocity<0 then yvelocity=yvelocity+0.08
if playerspeedmono > 0 then playerspeedmono=playerspeedmono-0.08
if playerspeedmono < 0 then playerspeedmono=playerspeedmono+0.08
if straferspeedmono > 0 then straferspeedmono=straferspeedmono-0.08
if straferspeedmono < 0 then straferspeedmono=straferspeedmono+0.08

if playerspeed>0
playerspeed=playerspeed-0.035 'non strafing speed decays until zero in strafe mode
else if playerspeed<0
playerspeed=playerspeed+0.035
end if

if up and straferspeed< 5.5
straferspeed=straferspeed+0.35 'And also pressing up key (but not exceeding speed limit)
play sound 6,100,175,1
else if down and straferspeed> -5.5
straferspeed=straferspeed-0.35 'And also pressing down key (but not exceeding speed limit)
play sound 7,0,110,1
end if

if pressed (56) 'Multi Strafemode overrides
if right
rotateship=rotateship+4.5
else if left
rotateship=rotateship-4.5
end if
end if

else 'If NOT pressing the strafe button in Multi-flight mode

if straferspeed<0 then straferspeed=straferspeed+0.035 'strafing speed decays while not strafing
if straferspeed>0 then straferspeed=straferspeed-0.035

if xvelocity>0 then xvelocity=xvelocity-0.065 'decays mono flight speed in both directions until 0
if xvelocity<0 then xvelocity=xvelocity+0.065
if yvelocity>0 then yvelocity=yvelocity-0.065
if yvelocity<0 then yvelocity=yvelocity+0.065
if playerspeedmono > 0 then playerspeedmono=playerspeedmono-0.08
if playerspeedmono < 0 then playerspeedmono=playerspeedmono+0.08
if straferspeedmono > 0 then straferspeedmono=straferspeedmono-0.08
if straferspeedmono < 0 then straferspeedmono=straferspeedmono+0.08

playerxdir= -sin(rotateship)
playerydir= cos(rotateship)

yposship= yposship-(playerydir*-playerspeed)+(playerydirstf*straferspeed)+yvelocity
xposship= xposship+(playerxdir*playerspeed)+(playerxdirstf*straferspeed)+xvelocity

if up
if playerspeed < 5.5
playerspeed=playerspeed+0.15
play sound 1,50,155,1
end if
else if down
if straferspeed > 0 then straferspeed=straferspeed-0.325 'All transitional speeds must also decrease at the push of the brake button.
if straferspeed < 0 then straferspeed=straferspeed+0.325
if xvelocity>0 then xvelocity=xvelocity-0.325
if xvelocity<0 then xvelocity=xvelocity+0.325
if yvelocity>0 then yvelocity=yvelocity-0.325
if yvelocity<0 then yvelocity=yvelocity+0.325
if playerspeedmono > 0 then playerspeedmono=playerspeedmono-0.325
if playerspeedmono < 0 then playerspeedmono=playerspeedmono+0.325
if straferspeedmono > 0 then straferspeedmono=straferspeedmono-0.325
if straferspeedmono < 0 then straferspeedmono=straferspeedmono+0.325
if playerspeed > 0
playerspeed=playerspeed-0.325 'Active speed
play sound 0,50,45,1
end if
end if

if pressed (56) 'Multi Overides; speed limit, brake becomes reverse, left/right turn tighter
if up
playerspeed=playerspeed+0.185
play sound 5,50,235,1
else if down
playerspeed=playerspeed-0.15
play sound 4,50,60,1
else if left
rotateship=rotateship-4.5
else if right
rotateship=rotateship+4.5
end if
end if
end if
end if 'END FLIGHT CONTROLS


'Other controls SHARED by ALL flightmodes

if left
rotateship = rotateship-2.25
'play sound 8,50,50,1
else if right
rotateship = rotateship+2.25
'play sound sound 9,50,50,1
end if

if pressed (3)'F; turns on MULTI flightmode
if astmode = 1
if playerspeed > 8.5 then play sound 11,50,255,65535
astmode = 0
if playerspeed >= 5.5 then play sound 11,50,175,65535
astmode = 0
if playerspeed >= 3 and playerspeed < 5.5 then play sound 11,50,175,65535
astmode = 0
if playerspeed >= 1.5 and playerspeed < 3 then play sound 11,50,135,65535
astmode = 0
if playerspeed > 0 and playerspeed < 1.5 then play sound 11,50,120,65535
astmode = 0
if playerspeed <= 0 then play sound 11,50,100,65535
astmode = 0
else
astmode = 0
end if
else if pressed (5)'G; Turns on MONO flightmode
if astmode = 0
play sound 10,50,110,5
astmode = 1
else
astmode = 1
end if
end if

draw frame
wend

10-06-2009 23:17

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

Bonehead

Oops, so, I'm a bonehead. The viewport was working fine, I just had transparent tiles as part of my map to try and see if a canvas image would come through as a background... And the transparent tiles were taking on other tiles' images when scrolling around. I was trying to do two things at once and forgot where I left off.

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.