Anyone know hot to resolve this?(2d coordinates re
Blitz3D Forums/Blitz3D Beginners Area/Anyone know hot to resolve this?(2d coordinates re
| ||
Hallo to all. It's about all day that i'm trying to solve a problem but don't know what to do. I have a program that track record of the mouse click and store the position of the mouse pointer in an array so i can access those coordinates later for drawing object at these coords. The problem is that this method works well if all the drawing operations are on screen.....but if i've a playfield much bigger that the screen? I have a playfield of 2000 * 2000 and the screen is displayed at 0,0 (x and y pos go from 0,0 to 2000,2000) i want to track record even of the point that are actually outside of the screen...if i use the command "origin"don't work because the record are always stored as i draw onscreen....What can i do? What's the method of record coordinates that are ouside of the screen res?(like track record of pixel 1500,750?) I hope it's not a tricky work because i have much code to change -_-' |
| ||
I'm not sure I really understand what you want but I think you just need to convert your mouse click positions to world coords, by adding the mouse x,y positions to the screen's woord coords. That is, the top-left corner of the screen should have a position (offset) in your 2000*2000 world - just add the mouse x,y to this. |
| ||
Just subtract the location of the top left corner of the screen in the world from the location of the point in the world. If your world is 1000x1000 and your screen is 100x100 and the top left corner of the screeen is at 200,200 in the world when the player clicks the center of it, then the point they clicked is at 50,50 in the screen and 250, 250 in the world, and if you then move the screen to the right by 50 pixels so it is as 250, 200, and then subtract that from the point's world location of 250, 250, then you are left with 0, 50, which is the point at which to plot the point on the current viewport. |
| ||
I think i understand what you are telling me. My world start at 0,0 and end at 2000,2000. I use to set the points to place object this function: set_path(mousex(),mousey() I must change into this set_path([screenxpos-mousex()],[screenypos-mousey()]) if i have understand well..... Another method that i have thinked is use the keyboard to scroll the world,and at the center of the world i place a sort of "aiming" circle,and set the points at the circle position...sot the function is simple: positionX=xworld-320 positionY=yworld-240 (if the screen if 640*480...). But now that i have read much more deep the post of big10p i think that his tips works best:the formula is (i hope...) xpath=xoffset+mousex() ypath=yoffset+mousey() Right? |
| ||
Nope...the formula don't work....if i make this the mouse rest in screen coords...and the path also. I give up......i try playing with screen offset (and the only command to do this in blitz is origin)but all change that i made give strange result...but none works. |
| ||
I think Swift has understand well...but effectively i don't know how to practice it's information... |
| ||
A brief explanation. I set up a playfield of 1000 * 1000 (i have used the standard tileimage command) from 0,0 to 1000,1000. The playfield start at 0,0 and is wide 640*480. I decide to plot a pixel at 800*800 world coords..... So i use the command origin to sroll the playfield....i use 2 text command to track the mouse position(but the mouse position is relatives to screen coords). How can i change the 2 text command (that actually just print the mouse x and y position...)to print the actual mouse x and y position BUT in playfield coordinates?? I think that this is the problem....and on top of that i want the mouse to stay always on screen and not follow the playfield..so i think it's tricky use of the origin command...too tricky for me! (the program after i have set up 10 points move an object trough all the points starting from point 1 to arrive at point 10...a sort of a path movement algo...but if i don't know how to translate screen coords in world coords the function of the movement don't work because my array are always full of screen coords and not of world coords..) |
| ||
Here's the code...bad writted because of the many tentatives of correction...commented in italian...and use of xlntii.... the code of the path setting are just under the ;M A I N text... For test the movement you must create first a path of 9 points...then load an image (there's a requester...)...then set up the speed...then try the current path...that's all. I give up completely.....all serious games require this functionality and i don't know how to make this,so i give up(the code above is non-functional...so to see anything move you must scroll the screen with the keyboard) Feel free to take any part of this code (i don't think it's of use to anyone but...). |
| ||
I have reproduced the error in a much smaller code to read! The eror is the same...a sort of mirror around the center of the world axis (0,0)... Type oggetto Field posx Field posy End Type Graphics 640,480,32,1 SetBuffer BackBuffer() Global terreno=LoadImage("terreno.bmp") ;a simple texture of 256*256 Global enemy=LoadImage("enemy.bmp") MidHandle enemy Global screenx=0 Global screeny=0 Global posx=200 Global posy=200 Global offset=1 While Not KeyHit(1)=True Cls x=MouseX() y=MouseY() mouse1=MouseHit(1) Origin screenx,screeny MapTiles() ;Origin 0,0 If KeyDown(200)=True Then screeny=screeny+1 If KeyDown(208)=True Then screeny=screeny-1 If KeyDown(205)=True Then screenx=screenx+1 If KeyDown(203)=True Then screenx=screenx-1 If KeyHit(57)=True Then screenx=0:screeny=0 ;if i hit the spacebar Rect MouseX(),MouseY(),9,9 ;Origin screenx,screeny If mouse1=True create_enemy(screenx+MouseX(),screeny+MouseY()) EndIf draw_enemy() Origin 0,0 Color 255,255,255 Text 50,400,("Mouse X world coords:"+(screenx-MouseX())) Text 50,410,("Mouse Y world coords:"+(screeny-MouseY())) Color 255,0,0 Text 50,430,("X offset world coords:"+screenx) Text 50,440,("Y offset world coords:"+screeny) Color 0,0,255 Text 50,450,("X mouse world coords:"+(screenx+MouseX())) Text 50,460,("Y mouse world coords:"+(screeny+MouseY())) ;If MouseHit(1)=True Flip Wend Function MapTiles() tilex=0 tiley=0 For tiley=0 To 2560 Step 256 For tilex=0 To 640 Step 256 DrawBlock terreno,tilex,tiley Next Next End Function Function draw_enemy1() DrawImage enemy,posx,posy posx=posx posy=posy+offset If posy =< 0 Then offset=1 If posy => 100 Then offset=-1 End Function Function create_enemy(x,y) a.oggetto=New oggetto a\posx=x a\posy=y End Function Function draw_enemy() For a.oggetto = Each oggetto DrawImage enemy,a\posx,a\posy Next End Function If i understand this i can make the other program work...so as my game... |
| ||
That's what happens when you change values at random in order to solve a bug.Type oggetto Field posx Field posy End Type Graphics 640,480,32,1 SetBuffer BackBuffer() Global terreno=LoadImage("c:\jacob\blitz\shooter test\floor104.bmp") ;a simple texture of 256*256 Global enemy=LoadImage("c:\jacob\blitz\5inarowicon.bmp") MidHandle enemy Global screenx=0 Global screeny=0 Global posx=200 Global posy=200 Global offset=1 While Not KeyHit(1)=True Cls x=MouseX() y=MouseY() mouse1=MouseHit(1) MapTiles() ;Origin 0,0 If KeyDown(200)=True Then screeny=screeny-1 If KeyDown(208)=True Then screeny=screeny+1 If KeyDown(205)=True Then screenx=screenx+1 If KeyDown(203)=True Then screenx=screenx-1 If KeyHit(57)=True Then screenx=0:screeny=0 ;if i hit the spacebar Rect MouseX(),MouseY(),9,9 ;Origin screenx,screeny If mouse1=True create_enemy(MouseX()+screenx,MouseY()+screeny) EndIf draw_enemy() Origin 0,0 Color 255,255,255 Text 50,400,("Mouse X world coords:"+(MouseX()+screenx)) Text 50,410,("Mouse Y world coords:"+(MouseY()+screeny)) Color 255,0,0 Text 50,430,("X offset world coords:"+screenx) Text 50,440,("Y offset world coords:"+screeny) Color 0,0,255 Text 50,450,("X mouse coords:"+MouseX()) Text 50,460,("Y mouse coords:"+MouseY()) ;If MouseHit(1)=True Flip Wend Function MapTiles() tilex=0 tiley=0 For tiley=0 To 2560 Step 256 For tilex=0 To 640 Step 256 DrawBlock terreno,tilex-screenx,tiley-screeny Next Next End Function Function draw_enemy1() DrawImage enemy,posx,posy posx=posx posy=posy+offset If posy =< 0 Then offset=1 If posy => 100 Then offset=-1 End Function Function create_enemy(x,y) a.oggetto=New oggetto a\posx=x a\posy=y End Function Function draw_enemy() For a.oggetto = Each oggetto DrawImage enemy,a\posx-screenx,a\posy-screeny Next End Function |
| ||
I have changed at random because i have run lost... But effectively the only modification that i see(except that you have eliminated many variables....early this code as the same as yours)is the draw enemy position function.. Effectively i haven't tryed to modify this.... So it's not the setpoint function that was wrong...but also the display function..... |
| ||
We all know that programming first really get hard when you reach the +/- dilemma. |
| ||
Yes. I must say a big "thank you" because now i have learned another way to move tiled background...just like the manual of Blitz say "the drawimage command is wrapped so it draws outside the screen".....now i use this "virtual offset" instead to play with Origin....i have modified my map placer/editor/mover with your modification and all goes exceptionally well! Now i can go to sleep @_@ |