Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline spyterweb  
#1 Posted : Friday, January 24, 2014 10:34:32 PM(UTC)
spyterweb

Joined: 1/22/2014(UTC)
Posts: 2
Location: Slippery Rock, Pennsylvania

I apologize ahead of time - I am completely new to Delta Engine. I cant find any good tutorials for how to "load content" and then access it in the game. I am using the Delta Engine editor and i click on content manager, then add - select an image. It appears on the right hand asset tree and I can see it in the viewport.

Inside my game class I am trying to load the image and display it on the screen using:

Code:
new Sprite(ContentLoader.Load<Material>("basic_character"), new Rectangle(position, size));


When I build and run the game, I get the error message:

Quote:
An unhandled exception of type 'DeltaEngine.Content.Material.UnableToCreateMaterialWithoutValidShaderName' occurred in DeltaEngine.dll


Does anyone know what I am doing wrong? Can I just create a Content folder in my Solution and load the sprites from there? It would be much easier than going through the editor.

Thanks in advance!

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Saturday, January 25, 2014 12:35:08 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Hi spyterweb,

You are trying to load a material for the sprite, which works if you would have a material called "basic_character", which I guess you don't have one for your content project you are using. Probably it is just an image called that. Simply use the image constructor to load your sprite:
Code:
new Sprite("basic_character", new Rectangle(position, size));


Alternatively you can of course also create a material from your image and then pass that into the Sprite constructor:
Code:

var myMaterial = new Material(ShaderFlags.Position2DTextured, "basic_character");
new Sprite(myMaterial, new Rectangle(position, size));


For details you can check the Sprite class or look at the SpriteTests.
Offline Benjamin  
#3 Posted : Saturday, January 25, 2014 12:38:32 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Originally Posted by: spyterweb Go to Quoted Post

Does anyone know what I am doing wrong? Can I just create a Content folder in my Solution and load the sprites from there? It would be much easier than going through the editor.


Yes you can, just set the DiskContentLoader at the beginning of your app and then you are free to use simple Content dropped into your local Content folder (obviously you will miss out on the great Editor features, but to get started it is totally fine to go this route):

Code:

	public class Program : App
	{
		public Program()
		{
			new Sprite("Logo", Vector2D.Half);
		}

		public static void Main()
		{
			ContentLoader.Use<DiskContentLoader>();
			new Program().Run();
		}
	}


PS: For this you would need a Logo.png (or .jpg) in your Content folder and you need to reference the DeltaEngine.Content.Disk project (or just use nuget, it is all in there).
Offline spyterweb  
#4 Posted : Saturday, January 25, 2014 1:31:51 AM(UTC)
spyterweb

Joined: 1/22/2014(UTC)
Posts: 2
Location: Slippery Rock, Pennsylvania

Brilliant!! That's EXACTLY what I was looking for! Thank you so much!
Offline Jothaka  
#5 Posted : Monday, April 7, 2014 6:03:13 PM(UTC)
Jothaka

Joined: 11/19/2013(UTC)
Posts: 6
Location: Hamburg

Hi everyone,

I revived this thread since my problem meets the topic, hope you don't mind ;)

I am trying to pick up Delta right now and have trouble loading Images.
Using your Tutorials and reading a bit through your GhostWars I created following code to test

Code:

class RotatingSprite :Sprite
    {
        public ScreenSpace screenSpace { get; protected set; }

        public RotatingSprite(ScreenSpace screenSpace)
                :base("Btn_1",Rectangle.One)
        {
            this.DrawArea = Rectangle.FromCenter(Vector2D.Half, screenSpace.FromPixelSpace(new Size(70, 70)));
            this.screenSpace = screenSpace;
            this.StartRotating(45);           
        }
}


If I use it like this, nothing shows up, if instead I try to load the image as material (ContentLoader.Load<Material>("Btn_1");)
I get a ContentNotFound Exeption.
I tried both ways for importing Content, adding it in the editor and creating a "Content"-Folder in the project directory and using ContentLoader.Use<DiskContentLoader>();
I get the Images displayed correctly in the Editor but still can't load them.

I tried:
-Restarting VS2012
-Rebuilding the project
-Deleting and adding the Images again in the Delta-Editor

Although it shouldn't matter in Delta, but all my images i tried to load are Power of Two, but don't now if this is connected ?_?


PS: While debugging around a bit I found a little error in the Vector2D QuadraticScreenSpace.FromPixelSpace(Vector2D): if your input Vector2D has negative Values the resulting Vector2D will always have a positive Y-Value! I think there is something wrong with the offset used for calculating Y, since i even get a positive value in Y when i insert a Vector2D.Zero!
Offline Benjamin  
#6 Posted : Tuesday, April 8, 2014 12:15:56 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Hi Jothaka,

We are currently restructuring the content types a bit to avoid confusion like this.

You have probably used an image in your Content folder and now you are trying to use it as a Material. Hopefully you are using the the latest DeltaEngine version and the \Content\<ProjectName>\ subfolder.

First things first, try to load your image like this:
Code:
var myImage = ContentLoader.Load<Image>("Btn_1");


If that works, you can pass it to a material constructor:
Code:

var myImage = ContentLoader.Load<Image>("Btn_1");
var myMaterial = new Material(ContentLoader.Create<Shader>(new ShaderCreationData(ShaderFlags.Position2DTextured)), myImage);


Since that is a bit cumbersome, you can use the much shorter version to create a material with an image name:
Code:

var myMaterial = new Material(ShaderFlags.Position2DTextured, "Btn_1");


And then you can pass the material to a Sprite to show it on screen:
Code:

var myMaterial = new Material(ShaderFlags.Position2DTextured, "Btn_1");
var mySprite = new Sprite(myMaterial, Rectangle.One);


Or use the even shorter version:
Code:

var mySprite = new Sprite("Btn_1", Rectangle.One);


However if you already fail to load your "Btn_1" image, then your problem is right there, you don't have it in your \bin\Debug\Content\<ProjectName>\ folder!

Again, we are currently reworking this system and will have a new streamlined content system up by next week.
Offline Jothaka  
#7 Posted : Tuesday, April 8, 2014 2:28:02 PM(UTC)
Jothaka

Joined: 11/19/2013(UTC)
Posts: 6
Location: Hamburg

Thanks for the quick reply :)

After a quick check I found out I really forgot to put it into the bin/debug/Content folder (only created a Content in project directory and put the files there).Blushing

Do the Images still have to be in the /debug/Content/ Folder even if I use the default ContentLoader (without saying he should use DiskContentLoader)?
At first glance I would have thought, that all Content I insert using the Delta Engine Content Manager by drag and drop on the viewport are available to be loaded without moving files around?!

I only just installed the new Editor vers 1.1. so I am still figuring out the changes made.
Well I am off to test again, I am exited to see your new content system when its released.

Thanks again!
Jothaka

Offline Benjamin  
#8 Posted : Tuesday, April 8, 2014 6:13:28 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
If you use the default ContentLoader (which is DeveloperOnlineContentLoader) all your content is automatically downloaded and managed for you, you only need to go into the \bin\Debug\Content\<ProjectName>\ folder when using the DiskContentLoader and putting some custom content in there. Normally using the Editor should work just fine. Let us know if you run into any trouble.
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.320 seconds.