.net - menu loading error in XNA project to load 3D menu -
i trying 3d menu in xna getting error following "the name 'item_ontap' not exist in current context." new xna programming.thank in advance.
//modelmenugame.cs public class modelmenugame : microsoft.xna.framework.game { graphicsdevicemanager graphics; spritebatch spritebatch; spritefont font; model menuitemmodel; vector3 cameraposition; matrix view; matrix projection; list<modelmenuitem> menu; int totalmenuitems = 4; rectangle leftregion; rectangle rightregion; int currentindex = 0; public event eventhandler ontap; public modelmenugame() { graphics = new graphicsdevicemanager(this); content.rootdirectory = "content"; targetelapsedtime = timespan.fromticks(333333); // extend battery life under lock. inactivesleeptime = timespan.fromseconds(1); } protected override void initialize() { // todo: add initialization logic here cameraposition = new vector3(-40, 10, 40); view = matrix.createlookat(cameraposition, vector3.zero, vector3.up); projection = matrix.createperspectivefieldofview(mathhelper.piover4, graphicsdevice.viewport.aspectratio, 1.0f, 1000.0f); menu = new list<modelmenuitem>(); leftregion = new rectangle(0, 0, graphicsdevice.viewport.width / 2, graphicsdevice.viewport.height); rightregion = new rectangle(graphicsdevice.viewport.width / 2, 0, graphicsdevice.viewport.width / 2, graphicsdevice.viewport.height); ontap = new eventhandler(item_ontap); currentindex = currentindex % totalmenuitems; if (currentindex < 0) { currentindex = totalmenuitems - 1; } else if(currentindex > totalmenuitems - 1) { currentindex = 0; } foreach (modelmenuitem item in menu) { if (item.index == currentindex) { item.selected = true; } else { item.selected = false; } } menuitemmodel = content.load<model>("modelmenuitem3d"); font = content.load<spritefont>("gamefont"); (int = 0; < totalmenuitems; i++ ) { int x = -20; modelmenuitem item = new modelmenuitem(this, menuitemmodel, view, projection); item.translation = new vector3(x + (i * 20), 0, 0); item.index = i; menu.add(item); } menu[0].selected = true; base.initialize(); }
here code //modelmenuitem.cs public class modelmenuitem : microsoft.xna.framework.gamecomponent {
model modelitem; public vector3 translation; public matrix view; public matrix projection; public int index; public bool selected; public int offset; public modelmenuitem(game game, model model, matrix view, matrix projection) : base(game) { // todo: construct child components here modelitem = model; view = view; projection = projection; offset = 5; } public void draw() { matrix[] modeltransforms = new matrix[modelitem.bones.count]; modelitem.copyabsolutebonetransformsto(modeltransforms); foreach (modelmesh mesh in modelitem.meshes) { foreach(basiceffect effect in mesh.effects) { effect.enabledefaultlighting(); effect.ambientlightcolor = color.white.tovector3(); if (selected) { effect.world = modeltransforms[mesh.parentbone.index] * matrix.createtranslation(translation + new vector3(0, 0, offset)); } else { effect.world = modeltransforms[mesh.parentbone.index] * matrix.createtranslation(translation); } effect.view = view; effect.projection = projection; } mesh.draw(); } }