Note that there are some explanatory texts on larger screens.

plurals
  1. POtrying to do image menu in XNA program and stuck at constructor error
    primarykey
    data
    text
    <p>this is the code for ImageMenuGame.cs. trying to do menu in Xna, practising for game development and it is showing error as constructor error. I am New to XNA. Also pasting the screenshot along with the code. thanks in advance.<img src="https://i.stack.imgur.com/2NPzn.jpg" alt="enter image description here"></p> <pre><code>namespace ImageMenu { /// &lt;summary&gt; /// This is the main type for your game /// &lt;/summary&gt; /// public class ImageMenuGame : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font; Texture2D texImageMenuItem; List&lt;ImageMenuItem&gt; Menu; int TotalMenuItems = 4; int index = 0; int currentIndex; public ImageMenuGame() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); // Extend battery life under lock. InactiveSleepTime = TimeSpan.FromSeconds(1); } /// &lt;summary&gt; /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// &lt;/summary&gt; protected override void Initialize() { // TODO: Add your initialization logic here Menu = new List&lt;ImageMenuItem&gt;(); base.Initialize(); } /// &lt;summary&gt; /// LoadContent will be called once per game and is the place to load /// all of your content. /// &lt;/summary&gt; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here texImageMenuItem = Content.Load&lt;Texture2D&gt;("Imageitem"); font = Content.Load&lt;SpriteFont&gt;("gameFont"); int X = 150; int Y = 240; for (int i = 0; i &lt; TotalMenuItems; i++) { ImageMenuItem item = new ImageMenuItem(new Vector2(X + i * (texImageMenuItem.Width + 20), Y), texImageMenuItem, spriteBatch); item.Index = index++; Menu.Add(item); } } /// &lt;summary&gt; /// UnloadContent will be called once per game and is the place to unload /// all content. /// &lt;/summary&gt; protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// &lt;summary&gt; /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here Vector2 tapPosition = new Vector2(); TouchCollection touches = TouchPanel.GetState(); if (touches.Count &gt; 0 &amp;&amp; touches[0].State == TouchLocationState.Pressed) { tapPosition = touches[0].Position; foreach(ImageMenuItem item in Menu) { item.Update(gameTime, tapPosition); if (item.Tap) { currentIndex = item.Index; } } } base.Update(gameTime); } /// &lt;summary&gt; /// This is called when the game should draw itself. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); foreach (ImageMenuItem item in Menu) { item.Draw(gameTime); } spriteBatch.DrawString(font, "CurrentIndex: " + currentIndex.ToString(), new Vector2(0,0), Color.White); spriteBatch.End(); base.Draw(gameTime); } } } </code></pre> <p>//ImageMenuItem.cs</p> <pre><code>namespace ImageMenu { /// &lt;summary&gt; /// This is a game component that implements IUpdateable. /// &lt;/summary&gt; public class ImageMenuItem : Microsoft.Xna.Framework.GameComponent { SpriteBatch spriteBatch; Texture2D texture; public Vector2 Position; public Vector2 Origin; public bool Tap; float timer = 0; const float MinScale = 0.8f; const float MaxScale = 1; float scale = 0.8f; public int index = 0; public Rectangle Bound { get { return new Rectangle( (int) (Position.X - Origin.X * scale), (int) (Position.Y - Origin.Y * scale), (int) (texture.Width * scale), (int) (texture.Height * scale)); } } public ImageMenuItem(Game game, Vector2 Location, Texture2D Texture, SpriteBatch SpriteBatch) : base(game) { // TODO: Construct any child components here { Position = Location; texture = Texture; spriteBatch = SpriteBatch; Origin = new Vector2 (texture.Width / 2, texture.Height / 2); } } /// &lt;summary&gt; /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// &lt;/summary&gt; public override void Initialize() { // TODO: Add your initialization code here base.Initialize(); } /// &lt;summary&gt; /// Allows the game component to update itself. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; /// // public override void Update(GameTime gameTime) // { // TODO: Add your update code here // base.Update(gameTime); // } public void Update(GameTime gameTime, Vector2 tapPosition) { // if the tapped position within the text menu item bound, // set Tap to true and trigger the OnTap event Tap = Bound.Contains((int)tapPosition.X, (int)tapPosition.Y); // Accumulate the game elapsed time timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; base.Update(gameTime); } public void Draw(GameTime gameTime) { if (Tap) { if (scale &lt;= MaxScale &amp;&amp; timer &gt; 200) { scale += 0.1f; } spriteBatch.Draw(texture, Position, null, Color.Red, 0f, Origin, scale, SpriteEffects.None, 0f); } else { if (scale &gt; MinScale &amp;&amp; timer &gt; 200) { scale -= 0.1f; } spriteBatch.Draw(texture, Position, null, Color.White, 0f, Origin, scale, SpriteEffects.None, 0f); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload