|
Post by Nicky Peter Hollyoake on Apr 16, 2006 8:45:49 GMT -5
hey how do i like make a clickable thing summit like this
if x over x then goto whereever
if i made like a lil cursor thing on the screen and in the middle they was like 1 player or 2 player how would i make so wen da cursor goes on it it goes to wherever i put it to go
don't think u'll know what i mean but if you do can u help me?
|
|
|
Post by GuppyB on Apr 16, 2006 15:58:12 GMT -5
be more specific, are you working on a text program, 2D or 3D?
...G
|
|
|
Post by James :) (aka Madcow) on Apr 17, 2006 6:10:40 GMT -5
you'll need to do this locate 1,2 print "hi there" x=mouse_x y=mouse_y chars$( x,y) print "x" if x=1 and y=2 then print"hello" endif
|
|
|
Post by dodic on Apr 17, 2006 16:14:14 GMT -5
That doesnt really work.
|
|
|
Post by GuppyB on Apr 17, 2006 19:36:02 GMT -5
Also, to my point (and my question to Nicky above):
If you create an object in 3D space, and had a 2D sprite cursor. How would you select the 3D object on the screen with the cursor?
I haven't had occasion to work this out yet in any of my programs, but would be interested in hearing the answer. My guess is that you would have to get the 2D coordinates of each the vertices from the buffer and then determine if the cursor was located within using an equation (would have to look it up) for finding if a point is located within. What OpenGL function you would use to cull the 2D coordinate, I don't know.
Anybody?
...G
...G
|
|
|
Post by Supermonkey on Apr 17, 2006 19:45:32 GMT -5
Heres some code to look at, I don't actually know if it works because I don't have b4gl installed atm.
dim tex,sprite dim mouseclicked dim mx2screen,my2screen dim sprxleft,sprxright,sprytop,sprybottom dim halfwidth,halfheight tex = loadtexture("testimg.png") sprite = Newsprite(tex) sprsetpos(100,100) while not mouseclicked cls locate 1,1 ' The mouse works on some weird coordinate system (0,0) = top left and (1,1) = bottom right ' Therefore multiplying mouse_x() by windowwidth() gives the round about mouse X position in pixels mx2screen = mouse_x()*windowwidth() ' Therefore multiplying mouse_y() by windowheight() gives the round about mouse Y Position in pixels my2screen = mouse_y()*480 printr "Mouse X = "+mx2screen+" MouseY = "+my2screen
'now we have the round about x and y position of the mouse in pixels, all we have to do is check to see if 'the mouse position is within the boundaries of the image: 'pseudo-code - The sprite is position at 100,100 but this is the centre of the sprite therefore 'the left boundary on the X axis would be the sprite width/2 - sprx() and the right boundary would be 'spritewidth/2 + sprx(). The same works for the y axis a crappy diagram is below '|-----------| c = sprite position (100,100) '| | c - xl = spritewidth()/2 '|xl c xr| xl = c-(spritewidth()/2) '| | xr-c = spritewidth()/2 '| | xr = c+(spritewidth()/2) '| ----------| 'Ok enough of the really crap explanation 'calculate the right and left x values 'I dont actually know how to get the sprite width or height so we will assume its 64x64 halfwidth = 64/2 halfheight = 64/2 sprxleft = sprx(sprite)-halfwidth : sprxright = sprx(sprite)+halfwidth sprytop = spry(sprite)-halfheight : sprybottom = spry(sprite)+halfheight printr "SPRXLEFT = "+sprxleft+" SPRXRIGHT"+sprxright printr "SPRYTOP = "+sprytop+" SPRYBOTTOM"+sprybottom 'now check to see if the mouse is within these co-ords if mx2screen > sprxleft and mx2screen < sprxright then if my2screen > sprytop and my2screen < sprybottom then print "b" endif endif swapbuffers() wend
cheers
Jon
|
|
|
Post by Nicky Peter Hollyoake on Apr 18, 2006 10:01:31 GMT -5
well im still not getting any of this. lol
|
|
|
Post by Nicky Peter Hollyoake on Apr 18, 2006 10:01:58 GMT -5
could you give me a cod that WORK!?
|
|
|
Post by GuppyB on Apr 18, 2006 12:02:13 GMT -5
SuperMonkey:
That's great but it doesn't answer my question. Your code is determining whether the cursor is on a 2D image sprite, my question was how would you determine if it was on a 3D object in 3D space?
...G
|
|
|
Post by Supermonkey on Apr 18, 2006 15:33:37 GMT -5
SuperMonkey: That's great but it doesn't answer my question. Your code is determining whether the cursor is on a 2D image sprite, my question was how would you determine if it was on a 3D object in 3D space? ...G Sorry I was answering nicky's question, I'm not so sure about yours, its something that I've wondered about also. Well its nice to see my efforts were appreciated. The code above IN THEORY is perfect. I just don't know if it works in basic4gl because I don't remember every sprite command. If you don't understand it maybe you should read it through. The explanation given goes into alot of detail about exactly what I am doing. Instead of just saying 'Give me code' why not ask about the parts of the given code that you don't understand and I or someone else could explain it to you? Sometimes I wonder why I bother [edit] Guppy, this post on Gamedev.net may help you out. I don't know how good it is I haven't read it through but its a start I suppose. www.gamedev.net/community/forums/topic.asp?topic_id=326569
|
|
|
Post by Nicky Peter Hollyoake on Apr 18, 2006 16:22:29 GMT -5
ive sorted my code out now kinda...
'mouse click to go to next page. dim x,y,a$ start: while true textmode(text_buffered) cls color (0,255,0) 'sorry locate 0,7:print"go to the 'c' and press space" locate 0,8:print"sorry i don't kno how to make it" locate 0,9:print"so that i can press anywhere" locate 0,10:print"to go to next page." color (255,0,0):locate 9,12:print"click here to go to game." x=mouse_x() * 100 y=mouse_y() * 100 color (0,0,255):locate x,y:print"x" charat$ (x,y) 'you could copy this code over and over again at the bottom here but 'that would just be to difficult they must be an easier way 'if you are reading this and you got any ideas could you email me at 'blue_common_eyes@hotmail.co.uk if scankeydown (vk_space) and x=9 and y = 12 then 'go to the c and press space. 'and you should go to the next page. color (0,0,255):locate 0,0:goto nextpage:endif drawtext() wend
nextpage: while true textmode (text_buffered) cls 'if it goes to this page it worked color (255,0,0):printr"yay it worked." color (0,255,0):printr"press b to go back." color (0,0,255):print"or press escape to cut off screen" drawtext() if keydown ("B") then goto start:endif wend 'finished
|
|
|
Post by Nicky Peter Hollyoake on Apr 18, 2006 16:23:03 GMT -5
sorry that i printed it twice.
|
|
|
Post by wybiral on Apr 18, 2006 16:24:02 GMT -5
One possible way to find out if a 3d object has been click on is to send out a ray... If you have the mouse's X and Y, then you can send a ray that will travel through, using the mouse X/Y as its startpoint. Then when you get a collision, it worked... Naturally, you dont have to use rays... You could use a line equation (algebra) which would be the quickest... But that would also return the objects behind it too... I guess you could use the a line equation... Find collision, and then find out which collision was closer...
|
|
|
Post by Supermonkey on Apr 18, 2006 17:43:26 GMT -5
Nicky Peter Hollyoake: Heres a good time to talk about posting questions. People could have solved this a while back had you been more specific (as guppyB said). Instead you had different people offering you different solutions to what was a very vague question. wybiral That seems to be the same method which is discussed in that thread I posted, it would be cool if someone could write an example.
|
|
|
Post by Nicky Peter Hollyoake on Apr 19, 2006 6:03:00 GMT -5
Ok.. but im still having a problem i can only move to the next page if i put my mouse over the c and press enter do you know how so i can make it go for all the letters?
|
|