listDictionaryからtexture2Dを取得する際に問題が発生しました。
これは私のLoadGraphicsクラスです:
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<Texture2D>("Graphics/Team Blue/Turret hull spritesheet"));
_blue_turret_hull.Add("rows", 1);
_blue_turret_hull.Add("columns", 11);
}
}
}
これは、Texture2Dを取得する必要があるTurretクラスです。
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"]; }
}
}
}
ここでのみ、次のエラーが発生します。
タイプ「オブジェクト」を「Microsoft.Xna.Framework.Graphics.Texture2D」に暗黙的に変換することはできません。明示的な変換が存在します(キャストがありませんか?)
listDictionaryに保存したことに問題があることはわかっています。そうすれば、必要なすべての情報を一度に取得できるからです。他にどのようにこれを行う必要がありますか?
前もって感謝します、
マーク・ダイケマ