Using GIFs with XNA - c#

I was looking for a way to use GIFs within XNA when I found this: http://xnagif.codeplex.com/
Can anyone tell me the proper steps in adding and linking this library to my project? I couldn't get it to work when I tried it, and I feel as though I might deleted/overwrite a necessary component to my project.

As I said, spritesheet animation is much easier with spritesheet than gifs and gives you much more flexibility, like storing multiple animations in the same image file.
This nice tutorial will help you get started on spritesheet animation in XNA. It shouldn't take long for you to develop a working animation library with this.
In short, XNA already has a parameter in its Draw method that allows you to draw only a small part of the full image (parameter: source). Using this, you can change the source every X second to make it look like an animated gif. I assure you that it really isn't too complicated and shouldn't be too long to implement (as I have done it myself several times already, always improving my animation engine)

Related

Need to use Tiled Map editor with Unity 4.3.4

I shifted to unity few weeks ago. I am developing a 2D platformer. For creating the maps I am using Tiled map editor from www.mapeditor.org . I have created a basic map. Included the tileSheet png and the .tmx file (saved as XML) in the Assets of the project. I am able to read the XML , that is all the gid's. But I don't know how to access a particular portion(tile) from the tileSheet corresponding to a gid.
I think for this I need to load sprite in the memory and select a tile (by specifying Height and width and coords) from texture memory to display it on screen. As given here :http://gamedevelopment.tutsplus.com/tutorials/parsing-and-rendering-tiled-tmx-format-maps-in-your-own-game-engine--gamedev-3104
but its for flash , how I can achieve same thing in Unity using C#. Notice the copyPixel stuff in the flash code. I thought I could use ReadPixels but it is used for reading from screen only not the texture memory.
Thanks.
If you're working in Windows then the Tiled2Unity Utility sounds like it will fit your needs. It exports Object Layers and was made with Unity 4.3 features in mind.
(Full disclosure: I'm the author of Tiled2Unity)
EDIT: Tiled2Unity is available for Mac users as well now. There is a command-line version for Linux users. (all free)
If you can describe more carefully your problem and what you are trying to do, maybe myself or someone can help you better, for example what exactly do you mean by "load a sprite into memory"? Or "select a tile"? Copying pixel data is SLOWWW, and hopefully you don't mean to be doing this in real time.
Here is my real advice though:
Have you checked out UTiled? It does tiled maps in 2D in Unity so I think it already does what you want and it's free.
There is also UniTMX... free.
There is also 'Tiled Tilemaps'... which is like $2.
I also built a system that can also do what I think you are trying to do (your link is broken, so I can't be sure).
The system I built is called 'Tiled to Unity' (you can search it in youtube to see if it does what you want). It allows you to attach gameObjects to tiles and have tile variants, and can do 3D tiles.
Anyway, trying to roll your own pipeline from Tiled into Unity is a ton of work, and with these tools available, I think it is almost certainly unnecessary... That's just imo.

C# Sidescroller starting advices

since this is my very first time trying to make yet simple but useable sidescroller I'd like to ask some questions and hopefully gather ideas to make a good engine that can change the position of an Image in the form depending on X position of the drawn game character. I'd basically like to recreate just few seconds of a Mario game.
The starting Idea (correct me if it's wrong / poorly performance / whatever) would be to create a picture long in width and whit fixed height and upon the press of, for example, A or D keys, the drawn character moves till a certain X point, after that, character gets locked in place and if the key is still pressed, the background image starts moving.
But the problem there would be the fix for collisions, would be possible to check for the X position of the drawn background picture and set "collisions" accordingly for the character?
Other questions : why picturebox should be avoided at all costs and use the form itself instead ? Placing the greater part of the classes methods inside a timer_tick event is the wrong approach ? I read somewhere that the best way to do games of this kind would be relying on infinite loops in the forms main method, but I simply cannot even think how this could possibly works, taking in count all the times we may need to get out of the loop and do different code in different places.
Any other different ideas/approach and direct links to further explanations would be greatly liked
Edit : yes i'd like to improve with windows forms before moving to xna/unity
Assumption: You want to make a little game and its your first time working with moving graphics and you're working with WindowsForms. Suggestion: try using a more advanced framework such as MonoGame or XNA and working your way through introductory documentation and tutorials. Also WPF has a more advanced graphics platform for doing things like drawing and 3D, you may want to give that a shot.
To expand on my comment a bit.
Windows Forms and GDI (the tech behind drawing) aren't meant for this kind of use. When GDI was created its purpose was essentially drawing lines and fonts on the screen. XNA is a really good framework for learning the basics up to professional design. Unfortunately the XNA framework is no longer supported by Microsoft and as such MonoGame is the recommended development route for managed .NET 3D and 2D game development.
The WPF provides basic access to Direct3D and Direct2D, and has 2D and 3D shapes and animations built into the framework and is what WPF is based on.
But you also have the choice, if need be, to create an XNA component and embed it in a Windows Form as demonstrated in these two tutorials.
XNA in Windows Forms I
XNA in Windows Forms II
Also using a Windows Forms Timer isn't recommended because they are unreliable. The .Net Framework provides a 'Server Timer' and a 'Threading timer' that can be used as well.
If you are really keen on using GDI for a game may I recommend reading about the basics of game programming (I think there are a few XNA docs on the subject) that should guide you on things like the basic run time loop, getting input, and simple physics.

Is it practical to port code from Flash to C#?

My goal is to gain a better understanding of the characteristics of C#, and become more comfortable creating simple apps. I am fairly competent with Flash (Actionscript 3), and found an old Tic-Tac-Toe game I'd written. I started wondering about porting this code into a C# application. Not knowing much about C#, I'm wondering how difficult the migration would be.
On the one hand, the underlying game logic is syntactically similar, and therefore would be easy to port.
However, as far as the graphics are concerned, I don't even know where to begin. So far, I've only exposed myself to Windows Forms and Console apps in C#.
I'm wondering if these Flash concepts have similar analogs in C#, or if the procedures and syntax are radically different:
Placing graphic elements on a stage
Rendering lines from start/end coordinates
Event listeners on movie clips
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
You may want to try developping your little game using Silverlight. Silverlight applications, coded using C# and Xaml, are pretty similar in form with flash applications, and you should find everything you need without trouble.
So I suggest you download the Silverlight SDK (free) and give it a try.
Firstly, Flash is to WPF (close enough) as ActionScript is to C#.
The WPF/Silverlight model is much more similar to Flex that it is to Flash. Everything is added to the UI tree as a object, even lines.
Likewise, adding event handlers to controls (like a button click) can be done in the "code behind" (the code that lives with the view), but the recommendation is to use the MVVM pattern. If you are new to the concepts of separation of concerns and unit testing, feel free to start with the simpler "code behind" method.
While WPF and Silverlight are very similar, I'd recommend starting with Silverlight as the SDK and available samples are richer. You can easily move onto WPF later on (though porting an application from Silverlight to WPF is not automatic).
Swapping images, as you mentioned, would be done via "Visual States" in Silverlight (or possibly changing the image reference, which is more "hacky").
Have a look at the following links to get started:
Learn # Silverlight.net
Silverlight on MSDN
Shapes and Drawing (Silverlight)
If you're looking specifically to do games and the like, you may wish to look into the free XNA framework. However, there will be differences as Flash gives you far more ability to "set up" things beforehand and modify them.
Placing graphic elements on a stage
If you go the XNA route, you will be drawing sprites using the spritebatch, you tell them where and how to draw and that's where they will go
Rendering lines from start/end coordinates
In windows forms you can do this via a simple System.Drawing call, however if you wish to do this in XNA, you will either have to make a 1 pixel square and stretch/rotate it to what you want, or use 3d primitives (Though this will limit you to a 1 pixel line)
Event listeners on movie clips
Look into delegates, but there isn't really an equivalent for movie clips to my knowledge
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
This is fairly simple, depending on what you mean. If you want to, say, animate a sprite. You can do this by moving the source rectangle or changing the texture of the spritesheet. If you mean the screen as a whole, this is mostly handled for you provided you use the spritebatch. In windows forms you'll have to do more of it yourself, but the base concepts are the same.
Overall it's not that bad, but if that doesn't sound appealing check out Silverlight. It's basically C# styled flash so you may find the transition easier.
Good luck and hope this helps.

C#: Creating a graphical screensaver

I am thinking about creating a screen saver. I have the whole thing, its graphics and the back-end kind of ready in my head. But I am not quite sure how to get the graphics out in code.
What I would like is a slide show of images with a bit of movement (kind of like the slide show in media center) and some floating text and shapes on top. The shapes somehow translucent.
I currently have a very simple static slideshow made in WinForms. Just a simple application that goes fullscreen and displays some images and pretends to fade them in and out in a hackish kind of way. But it is not very well made, and the performance is not very good. For example to prevent lag, I fade in a black square on top of the image, instead of fading in the actual image. Silly perhaps, but it kind of worked :p
Anyways, I would like to do a better job. But not sure where to start. Is WPF a good solution for this? Or should I look into DirectX or OpenGL? Is this something that could be handled well with XNA, or is that too game spesific?
WPF is not a bad idea. It takes advantage of DirectX and hardware acceleration for its animations and effects.
You will get better performance if you write this kind of stuff natively (against directx or opengl), but the cost of writing it will be much higher. It's quite possible you will not need that edge anyway.
Have a look at hanselman's baby smash (which is a full screen wpf app with animations) to get a grasp of what you can do with wpf.
Note: I did write a slide show kind of thingy in WPF way back, the key to getting this to work smoothly is loading up the images in a background thread and freezing it.
I guess XNA works well. There's a sample screensaver in C# Express, by the way.
Actually XNA works pretty well. For example: this is an (advanced) example of what can be made with XNA. The community is quite helpful and XNA has great potential.
A few weeks ago I wrote a two-part article describing how to create a Windows screen saver with GDI+. I am not displaying a slide show in my screen saver, but instead I am randomly drawing shapes. I did however explain the fundamentals of creating a screen saver for Windows which should be of some help if you have never created a screen saver before.
Create a Screen Saver Using C# – Part 1
Create a Screen Saver Using C# – Part 2
If you want to go with just GDI and GDI+, I wrote some info here about how to speed them up when rendering images and drawing them to screen. There is also fully functional screen saver source code at the above link (which I wrote myself after digging for some of the more obscure screen saver details), in case that helps.
Recently I finished with my first WPF (I wanted to see, how it can be done with WPF) screen-saver. You can check-it out on YouTube. Try to see HD-version.
Though I never tried XNA, I'm really pleased with WPF so far. Easy and flexible. But I guess you probably wouldn't get an XNA-performance (or am I wrong here?).
You can google for GDI+ or WPF ScreenSaver-templates to start with.

Animation effect in .NET?

Can someone point me to a C# open source implementaion with a simple image animations.
e.g. I feed the input image to animator, and the animation code produces a few dozen of images which if displayed sequentially looks like animation.
I am not something extremely fancy - a simple DirectX filter like animations would do.
You would be look for a sprite then? Microsoft has tutorials on this including:
http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032273446&CountryCode=US
and general graphics in C# here:
http://www.microsoft.com/events/series/msdnvisualcsharp.aspx?tab=webcasts
Hmmm... I'm not sure if this is what you want, but I've have created a library called Transitions that lets you animate most properties of UI controls easily. You could use it to move the position of pictures, transition between pictures or grow and shrink pictures. But I'm not sure that this is exactly the effects you're after? Anyway, if it's any help, my library is here:
http://code.google.com/p/dot-net-transitions/

Categories