forums

TNT Basic Forums > Programming Q&A
Broblem with lines
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-20-2003 21:34

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

I've a problem with lines.. i use a line in my game as a laser-sight where the target 1 is moved by the arrow-keys and the target 2 is moved by the mouse. the problem is that it just looks like an old After Dark screensaver!!.. how do i make it update and not leave traces? i dont want to paint a black rectangel all over the screen for every frame.

help help help!!


'The code


graphics mode 640,480
hide mouse
set framerate max

'player
set pen colour blue
fill rect 0,0 to 60,10
copy image 0,0,60,10,white,true to 0

'target
set pen colour blue
fill rect 0,0 to 5,5
copy image 0,0,5,5,white,true to 1

set pen colour black
paint canvas
set pen colour white
frame rect 0,0 to 640,480

global int win = 0
global int playerx=320
global int targetx,targety
global int target1x,target1y=470,target2x,target2y=0

repeat

'move target
targetx=mouse x
targety=mouse y
target1x=playerx+30

'draw target-line
target2x=mouse x
procedure targetline()
set pen colour red
Line target1x,target1y to target2x,target2y
set pen colour black
fill rect 0,0 to 640,480
end proc

' draw sprites

'target
sprite 1,targetx,targety,0
'player
sprite 1,playerx,470,0


draw frame


'input
'move player
if pressed(123)'leftarrow
playerx=playerx-3
'draw target line
targetline()
else if pressed(124)'rightarrow
playerx=playerx+3
'draw target line
targetline()
else
playerx=playerx
'draw target line
targetline()
end if

until win=1




draw frame
wait mouse click

11-20-2003 21:36

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Proper code

Sorry.. i posted the wrong version of code..
this is the proper one.


graphics mode hardware 640,480
hide mouse
set framerate max

'player
set pen colour blue
fill rect 0,0 to 60,10
copy image 0,0,60,10,white,true to 0

'target
set pen colour blue
fill rect 0,0 to 5,5
copy image 0,0,5,5,white,true to 1

set pen colour black
paint canvas
set pen colour white
frame rect 0,0 to 640,480

global int win = 0
global int playerx=320
global int targetx,targety
global int target1x,target1y=470,target2x,target2y=0

repeat

'move target
targetx=mouse x
targety=mouse y
target1x=playerx+30

'draw target-line
target2x=mouse x
procedure targetline()
set pen colour red
Line target1x,target1y to target2x,target2y
end proc

' draw sprites

'target
sprite 1,targetx,targety,0
'player
sprite 1,playerx,470,0


draw frame


'input
'move player
if pressed(123)'leftarrow
playerx=playerx-3
'draw target line
targetline()
else if pressed(124)'rightarrow
playerx=playerx+3
'draw target line
targetline()
else
playerx=playerx
'draw target line
targetline()
end if

until win=1




draw frame
wait mouse click

'functions


11-20-2003 22:52

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

I am assuming it is the line from the target to the player that you are having problems with; my advice is to add a parameter to the target line procedure that tells the procedure what colour to draw the line in. Now here comes the clever bit. Call the procedure as you normally do with the parameter as red or whatever. Now, after you have drawn the frame, you call the procedure with balck, and the line is erased for the next time! This is a bit of a rough solution - you will probably want to have a proper backdrop image, so black lines will be no better than any other line... A final, if rather desperate solution, is to open a new canvas, draw the line on that canvas, copy it, clear the canvas and then use the result as a sprite. You will need to repeat it every frame, an it is unwieldy at best, but there you are.

I don't see why we can't have "special" graphics objects that mean that you can have a single line or triangle and use it like a sprite, with the ability to change co--ordinates and set sprite priorities... (nudges Mark). Ahhhh, but these are all distant dreams... we'll probably be waiting a while for all my crazed ideas to be implemented :-) Hope what I said helps.

-wyvern

11-20-2003 23:01

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Thanks!... i'll try the canvas thingy

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.