Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store Texture2D in a listDictionary in C#?
    primarykey
    data
    text
    <p>I am having problems with retrieving a texture2D from a listDictionary.</p> <p>This is my LoadGraphics Class:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Specialized; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Media; namespace Space_Game { public static class LoadGraphics { //global variable public static ListDictionary _blue_turret_hull; public static void LoadContent(ContentManager contentManager) { //loads all the graphics/sprites _blue_turret_hull = new ListDictionary(); _blue_turret_hull.Add("graphic", contentManager.Load&lt;Texture2D&gt;("Graphics/Team Blue/Turret hull spritesheet")); _blue_turret_hull.Add("rows", 1); _blue_turret_hull.Add("columns", 11); } } } </code></pre> <p>This is the Turret class the should retrieve the Texture2D:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; namespace Space_Game { class Turret_hull:GameObject { public Turret_hull(Game game, String team) : base(game) { if(team == "blue") { _texture = LoadGraphics._blue_turret_hull["graphic"]; } } } } </code></pre> <p>Only here it gives the following error:</p> <p><b>Cannot implicitly convert type 'object' to 'Microsoft.Xna.Framework.Graphics.Texture2D'. An explicit conversion exists (are you missing a cast?)</b></p> <p>I know there is a problem regarding the fact that I stored it in a listDictionary. I did that, because that way I could retrieve all necessary info at once. How else should I do this?</p> <p>Thanks in Advance,</p> <p>Mark Dijkema</p>
    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.
    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