forums

TNT Basic Forums > Programming Q&A
Keeping Sprite Centered
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-30-2002 19:09

Posted by:
Tony Rose

Click Here to Email Tony Rose   Find more posts by Tony Rose

I thought this would be easy to setup,but for some reason im having a hell of a time doing it.

I open a map viewport that covers my 640x480 screen and set the viewport offset to my TankX and TankY coordinates. I cant get the screen to center on the tank though. It DOES move the same speed as the tank ( I think),like if I press D it moves to the right and if I press A to the left. I just cant get the tank in the middle of the viewport. Im sure its something simple that im missing.

10-30-2002 19:24

Posted by:
John Treece-Birch

Find more posts by John Treece-Birch

Screen Position

I think the problem is that the viewport offset is set to the tank's position. Unfortunately, because the Set Viewport Offset command sets the top-left position of the screen, the tank will appear in the top-left of the screen.

I think you need to do something like this...

int offsetX,offsetY

offsetX=tankX-Viewport Width(n)/2
offsetY=tankY-Viewport Height(n)/2

if offsetX<0
offsetX=0
end if

if offsetY<0
offsetY=0
end if

Set Viewport Offset n,offsetX,offsetY

where n is your canvas/viewport number.

Thanks,
John

10-31-2002 04:07

Posted by:
Tony Rose

Click Here to Email Tony Rose   Find more posts by Tony Rose

Nope

That didnt work either...I sent you an email containing the source,I hope you dont mind. Its very small,65 lines of code and only 16k so I thought it would be OK.

10-31-2002 07:56

Posted by:
John Treece-Birch

Find more posts by John Treece-Birch

Tank Sprite

The problem is that the tank is not being drawn into the correct canvas. If you add the line...

Canvas 1

...to just before you draw the sprites, then that makes sure they are drawn into the canvas with the background map.

Thanks,
John

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.