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 class Game1 < Game def Game1 graphics = GraphicsDeviceManager.new this end def Initialize super #is this ok? #in C# i have base.Initialize() end #is this ok? #in C# i have protected override void Draw(GameTime gameTime) def Draw Game::GraphicsDevice.Clear Graphics::Color.CornflowerBlue #i don''t think this is is how to access the colour struct super gameTime #is this ok? #in C# i have base.Draw(gameTime) end end game = Game1.new game.run ps:allso posted on the Rubyforge page: http://rubyforge.org/forum/forum.php?thread_id=29605&forum_id=17160 -- Posted via http://www.ruby-forum.com/.
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::GraphicsYou 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 > endRuby 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() > endYep super should be fine> > #is this ok? > #in C# i have protected override void Draw(GameTime gameTime) > def DrawIn 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 structNot sure off the top of my head but I think it should be Color::CornflowerBlue> > super gameTimeThat 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!
Thanks mate I''ll put you suggestions to the test in the morning. Oh and I''m sort of using this as a pretext to learn some Ruby, also been playing with Hackety Hack but I don''t think I can larn the ruby way of OOP form it so I''m going for trial and error and forum. Thanks again. -- Posted via http://www.ruby-forum.com/.
Everything works great Made a little c# loader app to hide all of the require and include statements. Orion Edwards wrote:> ... and constructors are always def initialize, not def ClassNameThere is a problem in the fact that Xna has a function that is called every time the graphics device is lost(ex:alt+tab) and then returned witch is called Initialize() this function is basically responsible for initializing the main GraphisDevice object. Is there a way to call this function? -- Posted via http://www.ruby-forum.com/.
I''m not entirely sure I understand the problem, but "Initialize" is the one CLR method name that we don''t mangle. Is this a Ruby class that you''ve derived from an XNA type or just the XNA type directly? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Wednesday, November 19, 2008 1:53 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Everything works great Made a little c# loader app to hide all of the require and include statements. Orion Edwards wrote:> ... and constructors are always def initialize, not def ClassNameThere is a problem in the fact that Xna has a function that is called every time the graphics device is lost(ex:alt+tab) and then returned witch is called Initialize() this function is basically responsible for initializing the main GraphisDevice object. Is there a way to call this function? -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081120/0105b497/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.jpg Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081120/0105b497/attachment-0001.jpg>
The change was only committed about three weeks ago. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 19, 2008 5:54 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Ah. I gave some bad advice re that one method then. Sorry :-( Curt Hagenlocher wrote: I''m not entirely sure I understand the problem, but "Initialize" is the one CLR method name that we don''t mangle. Is this a Ruby class that you''ve derived from an XNA type or just the XNA type directly? -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Wednesday, November 19, 2008 1:53 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Everything works great Made a little c# loader app to hide all of the require and include statements. Orion Edwards wrote: ... and constructors are always def initialize, not def ClassName There is a problem in the fact that Xna has a function that is called every time the graphics device is lost(ex:alt+tab) and then returned witch is called Initialize() this function is basically responsible for initializing the main GraphisDevice object. Is there a way to call this function? -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94A72.EC4E9570] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081119/677b9686/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081119/677b9686/attachment.jpg>
Curt Hagenlocher wrote: Hi> Is this a Ruby class that you''ve derived from an XNA type or just the XNA type > directly?Well making a game using Xna basically meas inheriting the Game class present in Xna and implementing it''s methods so yes it''s a ruby class that gets derived from the Microsoft.Xna.Framework.Game class. The structure required by your main game class is as follows: -the constructor witch in c# is identified by the class name and in ruby as initialize -the graphic initialization/reinitialization method identified by the name "Initialize", this is the one that is making problems. -methods for both loading and unloading content -an update method and a draw method witch make up the actual game loop. So again my question is how can I call the graphics initialization function "Initialize", from Ruby, when it has the same name as a ruby constructor. -- Posted via http://www.ruby-forum.com/.
There shouldn''t be a conflict in recent versions of IronRuby. "Initialize" != "initialize" now. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Thursday, November 20, 2008 6:00 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Curt Hagenlocher wrote: Hi> Is this a Ruby class that you''ve derived from an XNA type or just the XNA type > directly?Well making a game using Xna basically meas inheriting the Game class present in Xna and implementing it''s methods so yes it''s a ruby class that gets derived from the Microsoft.Xna.Framework.Game class. The structure required by your main game class is as follows: -the constructor witch in c# is identified by the class name and in ruby as initialize -the graphic initialization/reinitialization method identified by the name "Initialize", this is the one that is making problems. -methods for both loading and unloading content -an update method and a draw method witch make up the actual game loop. So again my question is how can I call the graphics initialization function "Initialize", from Ruby, when it has the same name as a ruby constructor. -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Note that "initialize" (lower-case) doesn''t manifest itself as a CLR constructor for the derived class. The derived Ruby class is currently represented by a CLR type that has a single ctor taking RubyClass. We are working on improving .NET interop here. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Curt Hagenlocher Sent: Thursday, November 20, 2008 6:56 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache There shouldn''t be a conflict in recent versions of IronRuby. "Initialize" != "initialize" now. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Thursday, November 20, 2008 6:00 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Curt Hagenlocher wrote: Hi> Is this a Ruby class that you''ve derived from an XNA type or just the XNA type > directly?Well making a game using Xna basically meas inheriting the Game class present in Xna and implementing it''s methods so yes it''s a ruby class that gets derived from the Microsoft.Xna.Framework.Game class. The structure required by your main game class is as follows: -the constructor witch in c# is identified by the class name and in ruby as initialize -the graphic initialization/reinitialization method identified by the name "Initialize", this is the one that is making problems. -methods for both loading and unloading content -an update method and a draw method witch make up the actual game loop. So again my question is how can I call the graphics initialization function "Initialize", from Ruby, when it has the same name as a ruby constructor. -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Curt Hagenlocher wrote:> There shouldn''t be a conflict in recent versions of IronRuby. > "Initialize" != "initialize" now.Ok so I used the Upper cased Initialize and I get this exception: " wrong number or type of arguments for `Initialize'' " but Initialize doesn''t accept any parameters. Note there might be something wrong with the code I wrote if someone thinks that I will make the source available -- Posted via http://www.ruby-forum.com/.
Here is the source Can anyone figure why it won''t work? Attachments: http://www.ruby-forum.com/attachment/3065/Opal.zip -- Posted via http://www.ruby-forum.com/.
It would probably be useful if you could describe more specifically what isn''t working. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Sunday, December 14, 2008 6:28 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Here is the source Can anyone figure why it won''t work? Attachments: http://www.ruby-forum.com/attachment/3065/Opal.zip -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
As you say "Initialize" is different from "initialize" so I have the the constructor: def initialize graphics = GraphicsDeviceManager.new self super end witch works and then i have the Initialize procedure def Initialize super end witch manages the actual 3d viewport, it is called every time the 3d viewport needs reinitialization(like an ALT+TAB) when I try to run the script I get: " wrong number or type of arguments for `Initialize'' " the thing is Initialize doesn''t have any parameters, is it still being treated as a constructor? -- Posted via http://www.ruby-forum.com/.
I''ve already posted about this issue weeks ago. I was playing iwth XNA too. The IronRuby it''s not passing correctly the parameters for the super class methods. 2008/12/15 Gabriel Rotar <lists at ruby-forum.com>:> As you say "Initialize" is different from "initialize" > so I have the the constructor: > > def initialize > graphics = GraphicsDeviceManager.new self > super > end > > witch works > and then i have the Initialize procedure > > def Initialize > super > end > > witch manages the actual 3d viewport, it is called every time the 3d > viewport needs reinitialization(like an ALT+TAB) when I try to run the > script I get: > " wrong number or type of arguments for `Initialize'' " > the thing is Initialize doesn''t have any parameters, is it still being > treated as a constructor? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
Dudu Bai?o wrote:> The IronRuby it''s not passing correctly the parameters for the super > class methods.That is a bummer :( Hopeful IronRuby will improve over time. Guess I''ll try with IronPython -- Posted via http://www.ruby-forum.com/.
IronRuby is still in "alpha". CLR interop is a place we know is still particularly weak. IronPython just released version 2.0, and is considerably more mature. If your goal is to have a fairly polished dynamic language that runs on .NET, then IronPython is probably a better choice. If you like Ruby and don''t mind a few hiccups, then your willingness to file problem reports for issues that you find will be of great help to us. Things are likely to be a bit slow over Christmas, but I''ll see if I can get this fixed before the end of the year. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar Sent: Monday, December 15, 2008 12:49 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache Dudu Bai?o wrote:> The IronRuby it''s not passing correctly the parameters for the super > class methods.That is a bummer :( Hopeful IronRuby will improve over time. Guess I''ll try with IronPython -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Thanks Curt! I''ll be waiting for. :) 2008/12/16 Curt Hagenlocher <curth at microsoft.com>:> IronRuby is still in "alpha". CLR interop is a place we know is still particularly weak. IronPython just released version 2.0, and is considerably more mature. If your goal is to have a fairly polished dynamic language that runs on .NET, then IronPython is probably a better choice. If you like Ruby and don''t mind a few hiccups, then your willingness to file problem reports for issues that you find will be of great help to us. > > Things are likely to be a bit slow over Christmas, but I''ll see if I can get this fixed before the end of the year. > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Gabriel Rotar > Sent: Monday, December 15, 2008 12:49 PM > To: ironruby-core at rubyforge.org > Subject: Re: [Ironruby-core] Xna+IronRuby+RubyNewb=headache > > Dudu Bai?o wrote: >> The IronRuby it''s not passing correctly the parameters for the super >> class methods. > > That is a bummer :( > Hopeful IronRuby will improve over time. > > Guess I''ll try with IronPython > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
Curt Hagenlocher wrote:> ... >If you like Ruby and don''t mind a few hiccups, then your >willingness to file problem reports for issues that you find will be of >great help to us.Ruby is great, all though I''m new to the language I have grown attached to it. I''ll try to give my feedback to the best of my ability because it deserves it.>... > Things are likely to be a bit slow over Christmas, but I''ll see if I can > get this fixed before the end of the year.I can''t wait for the fix. And a wish of "Happy Hollydays" to the whole Iron Ruby team and to the users of this discussion board. -- Posted via http://www.ruby-forum.com/.