Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active September 28, 2022 02:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/3896411 to your computer and use it in GitHub Desktop.
Save WillSams/3896411 to your computer and use it in GitHub Desktop.
MonoGame w/ IronPython Example
import os, clr
clr.AddReferenceToFile("MonoGame.Framework.dll")
clr.AddReferenceToFile("OpenTK.dll")
from Microsoft.Xna.Framework import *
from Microsoft.Xna.Framework.Graphics import *
class App(Game):
def __init__(self):
self.graphics = GraphicsDeviceManager(self)
self.Content.RootDirectory = os.getcwd() + "/Content"
def Initialize(self):
""" Allows the game to perform any initialization it needs to before starting to run. This is where it can query for any required
services and load any non-graphic related content. Calling base.Initialize will enumerate through any components and initialize them as well. """
# TODO: Add your initialization logic here
self.Initialize()
def LoadContent(self):
""" LoadContent will be called once per game and is the place to load all of your content. """
# Create a new SpriteBatch, which can be used to draw textures.
self.spriteBatch = SpriteBatch(GraphicsDevice)
#TODO: use this.Content to load your game content here
def Update(self, gameTime):
""" Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio. """
# For Mobile devices, this logic will close the Game when the Back button is pressed
if GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed:
self.Exit()
# TODO: Add your update logic here
Game.Update(gameTime)
def Draw(self, gameTime):
""" This is called when the game should draw itself. """
self.graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
#TODO: Add your drawing code here
Game.Draw(gameTime)
game = App()
game.Run()
@nightblade9
Copy link

@WillSams IronPython came back into the spotlight recently - they released a new version a couple of months ago, which is fantastic. Word is they're slowly progressing on IronPython 3 (Python 3), but 2.x (Python 2.7) seems quite stable/functional enough to actually build production things on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment