Понедельник, 06 Мая 2024, 01:57

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Форум игроделов » Программирование » Программирование .NET » Проблема при подключении Dll в XNA (СontentLoadException)
Проблема при подключении Dll в XNA
Alexandr2Дата: Пятница, 26 Августа 2011, 12:02 | Сообщение # 1
частый гость
Сейчас нет на сайте
Значит написал класс Sprite. Скомпилировал его в dll затем в новом проекте XNA подключил его,при загрузки спрайта через этот класс,выдает исключение. СontentLoadException

Класс спрайта в dll
Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SpriteLoad
{
         public class Sprite
         {
               //поля класса
            public  Texture2D spriteTexture;//сам спрайт
            public Vector2 positiontexture;//поззиция спрайта
                  
             int frameCount;//размер анимационной последовательности
             double timeFrame;//время показа одного спрайта
             int frame;//номер спрай та
             double totalEclipse;//время прошедшее с последнего показа спрайта

             //параметрический конструктор для анимации спрайта
             public Sprite(int frameCount, int framePerSec)
             {
                 this.frameCount = frameCount;
                 timeFrame = 1D / framePerSec;
                 frame = 0;
                 totalEclipse = 0;
             }
             //пустой конструктор
             public Sprite()
             {
             }
             //переход к следующему фрейму
             public void UpdateFrame(double eclipsed)
             {
                 totalEclipse += eclipsed;
                 if (totalEclipse > timeFrame)
                 {
                     frame++;//счетчик кадров
                     frame = frame % (frameCount - 1);//делние по модулю
                     totalEclipse = 0D;//текущее время показа одного фрейма
                 }
             }
             //рисованиеи текущего спрайта анимационной последовательности
             public void DrawAnimSprite(SpriteBatch spriteBatch)
             {
                 int frameWight = spriteTexture.Width / frameCount;//вычисляем ширину текстуры
                 int frameHeight = spriteTexture.Height;

                 //вычисляем прямоугольник для отрисовки спрайта
                 Rectangle rec = new Rectangle(frameWight * frame, 0, frameWight, frameHeight);

                 //рисуем кадр
                 spriteBatch.Draw(spriteTexture,positiontexture,rec,Color.White);
             }
             //загрузка  спрайта
             public void LoadSprite(ContentManager content, string fileName)
             {
                 spriteTexture = content.Load<Texture2D>(fileName);//вот здесь выдает исключение
             }
             //рисованиепростого спрайта
             public void DrawSprite(SpriteBatch spriteBatch)
             {
                 spriteBatch.Draw(spriteTexture, positiontexture, Color.White);
             }
         }
}



класс Game1
Code

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using SpriteLoad; //подключаем тот самый dll

namespace LoadSprite_Test
{
         /// <summary>
         /// This is the main type for your game
         /// </summary>
         public class Game1 : Microsoft.Xna.Framework.Game
         {
             GraphicsDeviceManager graphics;
             SpriteBatch spriteBatch;

             Sprite sprite;

             public Game1()
             {
                 graphics = new GraphicsDeviceManager(this);
                 Content.RootDirectory = "Content";

                 sprite = new Sprite(12, 10);
                 sprite.positiontexture = new Vector2(100, 100);
             }

             /// <summary>
             /// 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.
             /// </summary>
             protected override void Initialize()
             {
                 // TODO: Add your initialization logic here

                 base.Initialize();
             }

             /// <summary>
             /// LoadContent will be called once per game and is the place to load
             /// all of your content.
             /// </summary>
             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
                sprite.LoadSprite(this.Content,"Textures\\0");  
             }

             /// <summary>
             /// UnloadContent will be called once per game and is the place to unload
             /// all content.
             /// </summary>
             protected override void UnloadContent()
             {
                 // TODO: Unload any non ContentManager content here
             }

             /// <summary>
             /// Allows the game to run logic such as updating the world,
             /// checking for collisions, gathering input, and playing audio.
             /// </summary>
             /// <param name="gameTime">Provides a snapshot of timing values.</param>
             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
                 double eclipsed = gameTime.ElapsedGameTime.TotalSeconds;
                // sprite.UpdateFrame(eclipsed);

                 base.Update(gameTime);
             }

             /// <summary>
             /// This is called when the game should draw itself.
             /// </summary>
             /// <param name="gameTime">Provides a snapshot of timing values.</param>
             protected override void Draw(GameTime gameTime)
             {
                 GraphicsDevice.Clear(Color.CornflowerBlue);

                 // TODO: Add your drawing code here
                 spriteBatch.Begin();
                sprite.DrawAnimSprite(spriteBatch);
                 spriteBatch.End();

                 base.Draw(gameTime);
             }
         }
}





Сообщение отредактировал Alexandr2 - Пятница, 26 Августа 2011, 12:11
DemeronДата: Пятница, 26 Августа 2011, 12:19 | Сообщение # 2
User created in C++
Сейчас нет на сайте
Не знаком с C#, но я не вижу что бы ты экспортировал свой класс из длл.
Alexandr2Дата: Пятница, 26 Августа 2011, 12:27 | Сообщение # 3
частый гость
Сейчас нет на сайте
Quote (Demeron)
я не вижу что бы ты экспортировал свой класс из длл.


using SpriteLoad; //подключаем тот самый dll

пространство имен подключил же. У меня все функции этого класса видет

Можно даже сказать не проблема подключения а проблема загрузки спрайта из скомпилированой dll




Сообщение отредактировал Alexandr2 - Пятница, 26 Августа 2011, 12:31
DemeronДата: Пятница, 26 Августа 2011, 12:40 | Сообщение # 4
User created in C++
Сейчас нет на сайте
Quote (Alexandr2)
using SpriteLoad; //подключаем тот самый dll

Это вроде как импорт...
Alexandr2Дата: Пятница, 26 Августа 2011, 12:45 | Сообщение # 5
частый гость
Сейчас нет на сайте
Блин разобрлся,все норм. короче все ссылки в dll поставил.

Форум игроделов » Программирование » Программирование .NET » Проблема при подключении Dll в XNA (СontentLoadException)
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг