Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
284
members |
114
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
Simple Path Editor
[
back
]
Author:
pioj
| Viewed:
494
times | Language:
BlitzBasic 3D
| Category:
Basic Functions
;_ SIMPLE A-B PATH EDITOR v.01 ;_ Pioj 2009. Graphics3D 1024,768,16,2 SetBuffer BackBuffer() ;--- Type tPATHS Field nodeA Field x1 Field y1 Field nodeB Field x2 Field y2 End Type Global Path.tPATHS Global camera%=CreateCamera() CameraClsColor camera%,40,40,40 ;-- ; optional space for adding GUI... ;-- Global nodeimg%=CreateImage(3,3) SetBuffer ImageBuffer(nodeimg%) Color 0,0,255 Rect 0,0,ImageWidth(nodeimg%),ImageHeight(nodeimg%) Color 255,255,255 Rect 0,0,ImageWidth(nodeimg%),ImageHeight(nodeimg%),0 SetBuffer BackBuffer() Global lastconsole$ Global path_creado%=0 Global dibuja_linea%=0 Global pinta%=0 While Not KeyHit(1) Cls; RenderWorld ; ;If I press "S" Key , Save the path list to a File.. "last.txt" If KeyHit(31) Then ;-open output file in write mode fileout = WriteFile("last.txt") For Path.tPATHS = Each tPATHS ;- linia$="PATH "+numlin%+"|"+Path\x1+":"+Path\y1+"-"+Path\x2+":"+Path\y2 WriteLine fileout,linia$ numlin%=numlin%+1 ;- Next ;- CloseFile fileout lastconsole$="File Saved to: last.txt" ;- EndIf ;si pulso el izq del mouse, creo puntos de path If MouseHit(1) Then pinta%=pinta%+1 lastconsole$="Last point created at: "+MouseX()+":"+MouseY() If pinta% = 1 Then ;- Path.tPATHS=New tPATHS Path\nodeA=CopyImage(nodeimg%) MidHandle Path\nodeA ;- Path\x1=MouseX() Path\y1=MouseY() ;- dibuja_linea%=1 pinta%=2 ;- Else pinta% = 2 ;- Path\nodeB=CopyImage(nodeimg%) MidHandle Path\nodeB ;- Path\x2=MouseX() Path\y2=MouseY() ;- path_creado%=path_creado%+1 dibuja_linea%=0 pinta%=0 EndIf EndIf show_menu() ;- Flip False Wend ;-- End Function show_menu() ;- Color 60,60,60 Text MouseX()+2,MouseY()-10,MouseX()+":"+MouseY() ;- Color 255,255,255 Text 10,GraphicsHeight()-20,lastconsole$ If path_creado%>=1 And dibuja_linea%=0 Then ;- For Path.tPATHS = Each tPATHS ;- DrawImage Path\nodeA,Path\x1,Path\y1 Color 200,200,200 Text Path\x1-15,Path\y1-15,"A["+Path\x1+":"+Path\y1+"]" DrawImage Path\nodeB,Path\x2,Path\y2 Text Path\x2-15,Path\y2-15,"B["+Path\x2+":"+Path\y2+"]" Color 128,128,255 Line Path\x1,Path\y1,Path\x2,Path\y2 ;- Next ;- EndIf If dibuja_linea%=1 Then ;- DrawImage Path\nodeA,Path\x1,Path\y1 Color 200,200,200 Text Path\x1-15,Path\y1-15,"A["+Path\x1+":"+Path\y1+"]" Color 128,128,255 Line Path\x1,Path\y1,MouseX(),MouseY() ;- EndIf End Function
Author Comments:
This is a 2D path editor I did to help me while developing a 2D platform Game. Just Left-click the first point, then left-click again wherever you want.. and thats it!. Be free to modify the code anyway you like.. More resolution, scrolling, related coords to another path... - Unlimited Paths ( All is created by objetcs, so theres no Array limiting any max. number of paths..) - Simple AB Path Structure. Each path contains 2 image handlers (AB) and their XY coords. - It keeps info of any path created. - Save the paths to a file called "last.txt". <-- It can be exported to anything (.bb, .xml, binary data, etc.) - Quits with Esc key. Just mail me at carlosleci@gmail.com if you want some more stuff.. :)
Login or
create an account
to comment on this snippet