I'm trying to create a canvas HUD I can add over the existing non canvas HUD in the A-4K which will serve one purpose, to track targets (e.g. multiplayer or AI aircraft). The reason for this is that the target markers feature of the non canvas HUD doesn't work in newer versions of FG anymore. I am currently trying to get canvas to work before I start creating this (as I am completely new to canvas development). I have followed the wiki article http://wiki.flightgear.org/Howto:Add_a_2D_canvas_instrument_to_your_aircraft and created the following in order to simply display some text on the HUD glass to test it out.
- Code: Select all
var my_canvas = canvas.new({
"name": "hud-glass",
"size": [4,4],
"view": [768, 1024],
"mipmapping": 1
});
my_canvas.addPlacement({"node": "hud-glass"});
var group = my_canvas.createGroup();
var text = group.createChild("text", "optional-id-for element")
.setTranslation(10,20)
.setAlignment("left-center")
.setFont("LiberationFonts/LiberationSans-Regular.ttf")
.setFontSize(14,1.2)
.setColor(2,0,0)
.setText("This is a text element");
text.hide();
text.setText("Hello!").show();
Problem is, the text isn't showing. I've checked the console when I run FG and no errors associated with this come up. The hud-glass placement is referring to the model I added to the cockpit in A-4K/Models/Cockpit.xml which is textured but somewhat transparent. I have also referred to the above code nasal file in the set.xml
Any help would be much appreciated. Especially if someone could grab some code for the target tracking in a canvas HUD which should work when I add it. I understand I might have to make a .svg file for this to work as well?
Thanks