[Ironruby-core] Xna+IronRuby+RubyNewb=headache

Orion Edwards orion.edwards at open2view.com
Fri Nov 14 18:31:26 EST 2008


On 15/11/2008, at 6:00 AM, Gabriel Rotar wrote:

> Hi
> I'm tiring to run a whole XNA game from IronRuby but I'm having some
> trouble translating the code from c# to ruby. That might be because  
> I'm
> really new at Ruby.
> here is what I wrote so far
> Game = Microsoft::Xna::Framework::Game
> GraphicsDeviceManager =  
> Microsoft::Xna::Framework::GraphicsDeviceManager
> Graphics=Microsoft::Xna::Framework::Graphics

You can avoid all this by writing

include Microsoft::Xna::Framework

it's more-or-less the equivalent of using namespace

>
> class Game1 < Game
>
> def Game1
> graphics = GraphicsDeviceManager.new this
> end

Ruby uses 'self' instead of 'this', and constructors are always def  
initialize, not def ClassName

>
>
> def Initialize
>
> super
> #is this ok?
> #in C# i have base.Initialize()
> end

Yep super should be fine

>
> #is this ok?
> #in C# i have protected override void Draw(GameTime gameTime)
> def Draw

In ruby you should have def draw(game_time)

>
> Game::GraphicsDevice.Clear Graphics::Color.CornflowerBlue #i don't  
> think
> this is is how to access the colour struct

Not sure off the top of my head but I think it should be  
Color::CornflowerBlue

>
> super gameTime

That should be fine. Normally in ruby you don't need to pass arguments  
to calls to super, but I'm not sure how IronRuby handles this when  
interopping with the CLR...

>
> #is this ok?
> #in C# i have base.Draw(gameTime)
> end
> end
>
> game = Game1.new
> game.run
>

Last 2 lines look fine :-)

I'd really suggest you stop and step back a bit, and learn some of the  
basics of the ruby programming language.
Also note that C# uses UpperCamelCase for everything, whereas ruby  
uses lower_snake_case for everything (except class names)

IronRuby will translate these for you, so if you have a C# method  
called MoveAllZig(), then ruby code to call that will be move_all_zig

Good luck!


More information about the Ironruby-core mailing list