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

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline codesmith  
#1 Posted : Sunday, April 28, 2013 4:53:16 PM(UTC)
codesmith

Joined: 4/26/2013(UTC)
Posts: 46

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Since I finally managed to display a sprite, I'm wondering how the DrawArea works. Sorry if this is a stupid question :)

When I construct a new Sprite, how do I define a DrawArea for it so it's drawn in 1:1 proportions. Meaning no scaling up or down.

If I specify DrawArea of Rectangle.One the sprite seems to be outputted having double of the original pixel size.

Also is Sprite the fastest method to draw 2D images with position, rotation, color and opacity (alpha)?
-erno
Codesmith - Erno Pakarinen
Check my development blog @ blog.codesmith.fi

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

Offline internetfreak  
#2 Posted : Sunday, April 28, 2013 6:35:43 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
The Rectangle you give when creating the sprite is already your DrawArea. DeltaEngine uses the so called QuadraticScreenSpace to ensure a resolution independant drawing of your sprites. If you want to change the DrawArea before drawing, you can always use the DrawArea-Property of your sprite. For having a 1:1 drawing, you can use the ScreenSpace class. Simply add a Property of the ScreenSpace class to your gameclass (similar to the Renderer) and you will have it. Then you can use the FromPixelSpace method and fill in the necessary params, Delta will then convert it to a QuadraticScreenSpace value and you're done but remember that this value is resolution dependant so if you change the resolution (i.e the size of the game window), you have to recalculate the value so the rendering is ok again.
Maybe the delta staff can do it so we only specify the pixel size, then it will be rendered in correct proportions and if the resolution changes, it will automatically recalculated?
Anyway, you can read more about the ScreenSpace in the old wiki, this is one of the useful infos which are still ok to read :)

About your second question: The sprite is only one class which simplyfies the process of drawing an image. Internal there are other mechanism which will do the other stuff for you. In general, you don't have to worry about performance, Delta will do as much as possible to optimize the rendering and all other stuff (but that doesn't mean that you don't have to look at performance, even Delta cannot avoid framedrops if you write bad code but it helps you a bit to achieve good performance :) )
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#3 Posted : Sunday, April 28, 2013 6:50:40 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)
You can use Image.PixelSize, there are some examples in DeltaEngine.Rendering.Tests, we have however not written any final tutorial yet as the whole rendering system was changed this month. The DrawArea logic stays the same, but sprites are created in a very different way now (will be explained in a week).

In any case it is not recommended to draw in pixel space as your game will not scale up or down on mobile devices, tvs, consoles or different PC screen resolutions. You can do it, but it is not the recommended way. You can use any ScreenSpace class to convert from one space into another. By default QuadraticScreenSpace is used in Renderer (which does not exist anymore btw).

This code will display the DeltaEngineLogo image in the center of the screen, always in the exact pixel size (128x128) no matter which resolution you have. To make it rescale you could also put this code into the render loop to dynamically update when the resolution changes.
Code:

  Start(resolver, (Content content, Renderer renderer) =>
  {
    var image = content.Load<Image>("DeltaEngineLogo");
    var drawArea = Rectangle.FromCenter(Point.Half, renderer.Screen.FromPixelSpace(image.PixelSize));
    renderer.Add(new Sprite(image, drawArea));
  });
Offline Benjamin  
#4 Posted : Sunday, April 28, 2013 7:01:30 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)
Very good answer Internetfreak. My code snippet fits good below it :)
Offline codesmith  
#5 Posted : Sunday, April 28, 2013 7:44:13 PM(UTC)
codesmith

Joined: 4/26/2013(UTC)
Posts: 46

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Thanks guys :)

Anyhow, using exact pixel sizes is a bad thing anyhow because if you move your code to devices having screen with different sizes you will probably run into problems.

As I said in other thread I managed to port my particle system from my XNA based framework to Delta Engine. I still do the drawing probably quite stupidly because I manually command the Sprite to draw in game loop rather than using Renderer.Add. But this was the fastest way to port the XNA based system. There we draw things using SpriteBatches and my particle drawing routine was like this:

Code:
        
public virtual void Draw(SpriteBatch spriteBatch)
{
  spriteBatch.Draw(Texture, Position, null, 
    Color * Opacity, Rotation, Origin, Scale, SpriteEffects.None, Depth);
}


Does DE use spritebatching automatically with Renderer or is there a similar way to do it manually like in XNA? Or is the Renderer.Add() the preferred way to do drawing of stuff..
-erno

Edited by user Sunday, April 28, 2013 7:47:05 PM(UTC)  | Reason: Not specified

Codesmith - Erno Pakarinen
Check my development blog @ blog.codesmith.fi
Offline internetfreak  
#6 Posted : Sunday, April 28, 2013 8:00:36 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Originally Posted by: Benjamin Nitschke Go to Quoted Post
[...] You can use any ScreenSpace class to convert from one space into another. By default QuadraticScreenSpace is used in Renderer (which does not exist anymore btw). [...]


Benjamin, what does that mean? Does the Renderer not exist in that form anymore like it is now with the next release? Back in the earlier days, where 0.9.5 was still good, we could use Material2D.Draw to draw the image. Does this return or what it going on? I need to know because then I will suspend working on my project a little bit more (I'm currently at the very beginning of the project so I can change almost everything and I don't want to use code which is not useful anymore if I can have the new code in a few days :) )


@codesmith
Afaik Delta uses already sorting so use Renderer.Add for now to add your sprite to the list. The Sprite should have a property called "RenderLayer" or something like that where you can control the order of the sprites but without that, delta automatically sorts the sprites so it doesn't have to switch textures as often as unsorted (changing textures is very expensive regarding performance so delta will optimize it as much as possible. Just wait 1-2 weeks, you will see more and more how delta works because when the content server is ready, it will also optimize your textures and other stuff)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline codesmith  
#7 Posted : Sunday, April 28, 2013 8:10:11 PM(UTC)
codesmith

Joined: 4/26/2013(UTC)
Posts: 46

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Btw, I put this early version of DE based particle system (ported from XNA) to GitHub..

Check here if you want:

git://github.com/codesmith-fi/particletester.git
and throug browser:
GitHub - DE ParticleSystem tester

I'll fix problems tomorrow and submit this to the April competition :)

Btw, it's very robust and easily extendable particle system. Read more here: SmithNgine ParticleSystem

Only big missing thing basically is the XML loading (serialization) of parameters. I'll do that next. Adding new Modifiers and Generators is pretty easy since the re-factoring I did today.

If you are wondering the amount of classes, like MathUtil, Primitives and such, I ported them quickly from my framework because it was easier to use my existing classes than finding out if something already exists in Delta Engine. If I continue with this, I'll remove obsolete stuff and use DE classes instead.

-erno

Edited by user Sunday, April 28, 2013 8:28:59 PM(UTC)  | Reason: Added more info

Codesmith - Erno Pakarinen
Check my development blog @ blog.codesmith.fi
Offline Benjamin  
#8 Posted : Sunday, April 28, 2013 8:28:48 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)
Originally Posted by: internetfreak Go to Quoted Post
Benjamin, what does that mean? Does the Renderer not exist in that form anymore like it is now with the next release? Back in the earlier days, where 0.9.5 was still good, we could use Material2D.Draw to draw the image. Does this return or what it going on? I need to know because then I will suspend working on my project a little bit more (I'm currently at the very beginning of the project so I can change almost everything and I don't want to use code which is not useful anymore if I can have the new code in a few days :) )


Well, there is just no more thing like the Renderer, Renderables or even Sprites. Everthing is just an Entity now and you can dynamically extend its features and handling at any point in the code or editor.

It is still possible to use a "Sprite" class (which is just an Entity that has all common features like the old Sprite class) and don't care about how the underlying system works, but the recommended way is to use entities yourself in your game and share entity handlers between libraries and games. Even in our few sample games we notices many overlaps and by sharing some code, tons of code could be removed and simplified. This is obviously an ongoing process and the Game Jam in a week will be the first time people are going to use the new system.

Originally Posted by: internetfreak Go to Quoted Post

@codesmith
Afaik Delta uses already sorting so use Renderer.Add for now to add your sprite to the list. The Sprite should have a property called "RenderLayer" or something like that where you can control the order of the sprites but without that, delta automatically sorts the sprites so it doesn't have to switch textures as often as unsorted (changing textures is very expensive regarding performance so delta will optimize it as much as possible. Just wait 1-2 weeks, you will see more and more how delta works because when the content server is ready, it will also optimize your textures and other stuff)


True, Renderer.Add will put them in a list and you can control the render order via the DrawLayer property of each Renderable (e.g. a Sprite). This is similar with the new entity system, but some steps are not longer needed.

The point Internetfreak is making is very important because we want to encourage writing code as simple, quick and clean as possible and don't having to worry about performance impact so much. Instead we will try to optimize away many things you as a game programmer might not be aware of (e.g. how on iOS draw calls need to be reduced to an absolute minimum, while on Android other things are more important).
Offline codesmith  
#9 Posted : Sunday, April 28, 2013 8:42:51 PM(UTC)
codesmith

Joined: 4/26/2013(UTC)
Posts: 46

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
I now modified the ParticleSystem to add the sprites directly to the Renderer and removed any manual Draw()/Render() calls.

Then I compared the DE version of this Particle System to XNA version. XNA version is the original version from my framework without Delta Engine and directly using XNA features (Texture2D etc.).

XNA version uses Texture2D:s directly and noticeably faster than the DE version which uses Sprites. The XNA version runs smoothly with 10000 active particles but this DE version slows down after 1000...

But then, there probably is something wrong in the implementation and I need to make it more DE confortable :)
I'll look into it tomorrow. Now I'm tired.

I also have to check how much impact does it make if I use different versions of DE...
-erno

Edited by user Sunday, April 28, 2013 8:47:20 PM(UTC)  | Reason: Not specified

Codesmith - Erno Pakarinen
Check my development blog @ blog.codesmith.fi
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-2022, Yet Another Forum.NET
This page was generated in 0.103 seconds.