Question

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)
Was it helpful?

Solution

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.

OTHER TIPS

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:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top