forums

TNT Basic Forums > Programming Q&A
How do you "frame rect" by draggin the mouse?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

04-13-2006 05:12

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

[code]
int coordx
int coordy
<insert viewport scrolling with mouse variable integers here>
While
<insert viewport scrolling with mouse here>
if mouse button = true
int nowx
int nowy
nowx=mouse X
nowy=mouse Y
while mouse button = true
nowx=coordx
nowy=coordy
frame rect nowx,nowy to coordx,coordy
draw frame
wend
end if
wend
[/code]

here is what I used, but nothing happens. NOTHING!! No error logs, no crashing... nothing what so ever.

04-13-2006 05:43

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Okay... I got it drawing but not on top of the view port. How would you do that?

04-13-2006 05:55

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Done that as well...

if mouse button = true
canvas 1
set pen color green
set pen Transparency 50
while mouse button = true
coordx=mouse X
coordy=mouse y
Fill rect nowx,nowy to coordx,coordy
draw frame
wend
end if


But how do you make it so that the rectangle disppear after you let go?

04-13-2006 07:27

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

New Problem...

This is the program I have written. It is of a helicopter moved by the mouse on the screen. It is possible to rotate the helicopter with arrow buttons. By clicking relative to the helicopter, the map will slide that way (right of heli = move map right) However, I tried to make it, as long as I hold it, it keeps moving, yet in doesn't work, it only responses to single clicks, and the copter then stutters everywhere. Also, I tried to, while holding the click a green line will come from the helicopter to the mouse pointer, but the green lines just originates from some other point of the map, and doesn't exactly go towards the mouse button, except on the first click.

129 is the image of the helicopter.

Thanks for your help. (second time using TNT basic. First time was making that tron tutorial 2 years ago, which doesn't really tell you how do use sprites.)



graphics mode hardware 800,600
Load Images 130
int finish=2
int darkblue
load map 128
set current map 128
open map viewport 1,0,0,0 to 800,512
darkblue=Make colour (0,0,100)
set pen color darkblue
Sprite 129,400,256,000
draw frame

Set Sprite Transparency 128,10
Fill rect 0,512 to 800,600
draw frame
int coordx
int coordy
int viewportx
int viewporty
int nowx
int nowy
int rotation
int helix
int heliy

set Framerate Max

int movex
int movey

repeat
coordx = Mouse X
coordy = Mouse Y
viewportx = Viewport X offset (1)
viewporty = Viewport Y offset (1)
nowx = mouse X
nowy = mouse Y
rotation = Sprite Rotation (129)
movex = viewportx + ((coordx)-400)
movey = viewporty + ((coordy)-256)
helix=Sprite X (129)
heliy=Sprite Y (129)


if mouse button = true
canvas 1
set pen color green
set pen Transparency 50
while mouse button = true and movex>=0 and movey <= 987 and movey>=0 and movex <= 699

coordx=mouse X
coordy=mouse y
line helix,heliy to mouse x,mouse y
draw frame
Set Viewport Offset 1,movex,movey
line helix,heliy to mouse x,mouse y
draw frame
wend


end if


if true = Pressed (124)
int rotation
Set Sprite Rotation 129,(rotation + 10)
draw frame
end if

if true = Pressed (123)
int rotation
Set Sprite Rotation 129,(rotation - 10)
draw frame
end if
forever

04-18-2006 21:18

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Your basic algo is wrong...

Your 'movex' and movey' values should represent the difference between the mouse click (in world coordinates) and the copter's position (in world coordinates, that is viewport + scroll offset). Try these:

coordX=Mouse X + viewportX
coordY=Mouse Y + viewportY ' destination in world coords...

nowX= heliX + viewportX
nowY= heliY + viewportY 'source in world coordinates...

If you are moving the sprite, the formula is 'destination - source', but if moving the background it goes the other way, so it's 'source - destination'...
moveX= nowX - coordX
moveY= nowY - coordY


What you need to do now is set up a loop which will either increment or decrement the scroll offset based on the move variables, not just set the offset to them (if you see what I mean...). This will give you a pretty good representation of what you want, but to get it spot on you'll need to use bresenham's mid point line algorithm (hint hint!). Check my example in the Directory.

Hope this helps, and drop another line if you need anything else... Happy coding!

Danny (nods)

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.