realizer Posted March 27, 2014 Share Posted March 27, 2014 Hi guys,I am developing a html5 shooter with babylon.js. How can I draw a crosshair?What I tried:- crosshair via div, but it disappears in full-screen-mode- drawing it with the nativ canvas function (canvas.getContext("2d"), moveTo, lineTo, ...), but I get some errors, which make sense, because I'm in webGL mode and not in a 2d context). Do you have any soultions I could try? Thx Quote Link to comment Share on other sites More sharing options...
gryff Posted March 28, 2014 Share Posted March 28, 2014 Well a couple of options that might work if it is a fps game (making the assumption that there will be a gun and arm(s) as well) Create a plane with a crosshairs graphic ( a.png file with most of it transparent). Parent the plane to the camera. Adjust scale of the plane and distance from camera to your liking. Create a simple piece of geometry(mesh) in blender (or whatever you use to model ) to represent the cross hair, import it with gun/arms, and parent that to the camera cheers, gryff Quote Link to comment Share on other sites More sharing options...
Artem Posted March 28, 2014 Share Posted March 28, 2014 How about a simple sprite in front of a camera which its parent? Quote Link to comment Share on other sites More sharing options...
realizer Posted April 1, 2014 Author Share Posted April 1, 2014 Ok, thanks, that sounds sensible^^ But how can I set sprites or planes in front of the camera? Quote Link to comment Share on other sites More sharing options...
Artem Posted April 2, 2014 Share Posted April 2, 2014 Sort of this: function CrosshairInFrontOfCamera(crosshair, camera, distanceFromCamera, crosshairType) { crosshair.parent = camera; crosshair.position = camera.position.add(new BABYLON.Vector3(0, 0, distanceFromCamera)); // distance should be more than 0, of course crosshair.cellIndex = crosshairType;}CrossHairInFrontOfCamera(YourCrosshairVarNameHere, YourCameraVarNameHere, AnyDistanceYouLikeHere, ChooseYourCrosshairHere);I didn't tried it, but it should work just fine Good luck, realizer!Edit:That's just a thought though, there's always some better ways to do it. Added 'crosshairType' to choose from different crosshairs in a single 'png' file (same way as you use animations for sprites, but pick a single frame of it instead). realizer 1 Quote Link to comment Share on other sites More sharing options...
realizer Posted April 3, 2014 Author Share Posted April 3, 2014 Ok, thanks, I'll try it soon Quote Link to comment Share on other sites More sharing options...
realizer Posted April 7, 2014 Author Share Posted April 7, 2014 Ok, it works, but it doesn't move, when you move the camera. Are there some simple methods or do i have to code it by myself with the sprite position and the cameraDirection? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.