I want to use this wrapper in MonoGame but I get an error message if I use the code from the wrapper website.
Wrapper StatsIO
I downloaded the wrapper project and added the project to my solution in Visual Studio. After that, I created a reference from my project to the wrapper project.
Then, I copied this code to my project:
var client = new StatsIOClient("Client-ID", "Client-Secret");
await client.Statistics.CreateAsync("Stats-Id", "Username");
But something went wrong, because I get these error message:
Error CS1501: No overload for method 'CreateAsync' takes 2 arguments
(CS1501)
What is wrong with the code? How can I use the wrapper project in my Visual Studio project to send and receive leaderboard scores?
Dropbox link to my Visual Studio project: my project
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StatsIO.Objects;
using StatsIO;
namespace LeaderboardTest
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public async void NewClient()
{
var client = new StatsIOClient("Client-ID", "Client-Secret");
await client.Statistics.CreateAsync("Stats-Id", "Username");
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
NewClient();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
Related
I'm having a problem: When I create a window in OpenGL, using C#, my window starts to lag, and I cannot use the window (I cannot close, minimize, resize, etc.). And when I hover my mouse inside the window, my cursor becomes that blue wheel, meaning it's lagging. How can I fix it?
It's worth saying that I'm using OpenGL and OpenTK to display and use the window however I want.
This is my code for generating the window:
First, this is the “GameLoop” class, everything related to the game itself is derived from this class, it contains some abstract classes that I can override, so it's really useful.
public abstract class GameLoop
{
public GameWindow window;
public Vector2Int windowSize = new Vector2Int(1280, 768);
public void Run()
{
OnInitialize();
WindowManager.CreateWindow(windowSize.x, windowSize.y, "Engine", out window);
OnLoad();
while (WindowManager.IsRunning)
{
OnUpdate();
OnRender();
}
OnCloseWindow();
}
protected abstract void OnInitialize();
protected abstract void OnLoad();
protected abstract void OnUpdate();
protected abstract void OnRender();
protected abstract void OnCloseWindow();
}
class RunGameLoop
{
static void Main()
{
GameLoop loop = new EngineWindow();
loop.Run();
}
}
Secondly, I have this method in another class that is responsible for creating the window itself:
public static void CreateWindow(int width, int height, string title, out GameWindow window)
{
window = new GameWindow(GameWindowSettings.Default, NativeWindowSettings.Default);
Vector2Int res = new Vector2Int(width, height);
//windowSize = res;
IsRunning = true;
window.CenterWindow(Vector2Int.ToVec2i(res));
window.Title = title;
}
And finally, I have the main class, where I can use OpenGL and make my project:
public class EngineWindow : GameLoop
{
protected override void OnInitialize()
{
Debug.WriteLine("On Initialize");
}
protected override void OnLoad()
{
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.Lighting);
GL.ClearColor(Color.ToColor4(BackColor));
GL.Viewport(0, 0, windowSize.x, windowSize.y);
CreateMesh(cubeMesh);
}
protected override void OnUpdate()
{
}
protected override void OnRender()
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
angle += Time.deltaTime;
SetupViewport(sceneCamera);
RenderMesh(cubeMesh);
ControllCamera(sceneCamera);
GL.CullFace(CullFaceMode.Back);
GL.Finish();
window.SwapBuffers();
}
protected override void OnCloseWindow()
{
Debug.WriteLine("Ended");
// Clean up
GL.DeleteProgram(program);
GL.DeleteBuffers(1, ref vbo);
GL.DeleteVertexArrays(1, ref vao);
}
}
But, the issue is that when the window is created, it starts up fine, but becomes extremely laggy and I can't use the window.
What might be the issue, and how can I fix it?
I'm working on a game engine. Now assume we have a Game class:
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System.Drawing;
using static OpenTK.Graphics.OpenGL.GL;
namespace Test2
{
class Game : GameWindow
{
public Game(int width, int height)
:base(width, height)
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
}
}
}
And we have a medium in which to call a method for every frame.
Now assume the person creating a game, creates a file called ball_behaviour script:
using System;
using System.Drawing;
namespace Test2.Project.Behaviour
{
class Ball
{
public void Update()
{
}
public void init()
{
A2D.Background = Color.CornflowerBlue;
}
public void preInit()
{
}
}
}
And assume there are other files like it, which have the methods Update, and init. How can I call these methods from protected override void OnRenderFrame for example, in every class that's registered under Test2.Project.Behaiviour namespace? Thank you so much in advanced.
EDIT:The GameWindow class comes from OpenTK, which is the API I'm using to interface c# with OpenGL.
EDIT #2: Kind of like the way Unity does it.
you could use a virtual void that you than override which would be easier and faster to implement,have done this thing yesterday
I created a new MonoGame iOS solution in Xamarin Studio. After that, I added to following code to Game1.cs:
bool IsiOS = false;
if (Device.RuntimePlatform == Device.iOS)
IsiOS = true;
But I get an error message when I build the project.
if (Device.RuntimePlatform == Device.iOS)
System.InvalidOperationException You MUST call Xamarin.Forms.Init();
prior to using it.
What is wrong with my code? I don't know what I should add or change.
code(Game1.cs):
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Xamarin.Forms;
namespace NewTest.iOS
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
bool IsiOS = false;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
if (Device.RuntimePlatform == Device.iOS)
IsiOS = true;
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
code(Program.cs):
using System;
using Foundation;
using UIKit;
namespace NewTest.iOS
{
[Register("AppDelegate")]
class Program : UIApplicationDelegate
{
private static Game1 game;
internal static void RunGame()
{
game = new Game1();
game.Run();
}
static void Main(string[] args)
{
UIApplication.Main(args, null, "AppDelegate");
}
public override void FinishedLaunching(UIApplication app)
{
RunGame();
}
}
}
The Device class is part of Xamarin Forms. If you are using Xamarin Forms, then you must initialize it first. That is exactly what the error message is telling you.
I started days ago programming c# using monogame.
Today I got an error that says "Could not load asset as a non-content file".
Here's the code, I need much help.
List textures;
public Game1()
: base()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
// the below line errors
textures.Add(Content.Load<Texture2D>("Lol"));
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
SOLVED
Create a sub-folder under the Content one.
Call it "Assets"
Right click on the image file and right click
Properties -> Copy to Output -> Copy always
Go to the main class and set the RootDirectory as "Content.RootDirectory = #"Content\Assets";"
P.s. : Everytime you add a file, repeat 3rd and 4th step
I've looked around a lot.. and I haven't found anything to help me out.
This is the outcome I am looking for:
I am using XNA Game Studio 4.0, and I want to create my own library to use when making my game, so I don't have to rewrite code that I have previously used over and over every time I want to make a new game. So, I want to call in a library as a reference. My Library:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace iRaaptorLibraryXNA
{
public class XNALibrary
{
public static void consolePrint(string text)
{
var timeStamp = System.DateTime.Now.ToString(#"hh:mm:ss tt");
Console.WriteLine("[" + timeStamp + "] CONSOLE: " + text);
}
}
}
I use the consolePrint function a lot while debugging.
For example, if I wanted to print a line to show success, I'd like to be able to type
consolePrint("SUCCESS!")
and that prints it to console. I DONT want to have to repeatedly type in:
XNALibraryXNA.consolePrint("SUCCESS!");
I want to shorten it to just
consolePrint("SUCCESS!");
Here is my game code:
using iRaaptorLibraryXNA;
namespace xnaFun
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize()
XNALibrary.consolePrint("Initialized!");
}
protected override void LoadContent()
{
iRaaptorLibraryXNA.consolePrint("Loading content!"); // DOES PRINT TO CONSOLE
spriteBatch = new SpriteBatch(GraphicsDevice);
}
etc......
I hope I included enough information. ~iRaaptor
TL;DR I want to shorten
XMALibrary.consolePrint("text");
to
consolePrint("text");
Add this class to your library:
public class BaseGame : Microsoft.Xna.Framework.Game
{
protected void consolePrint(string message)
{
XNALibrary.consolePrint("Initialized!");
}
}
Your game class can then inherit from the basegame and use the consolePrint method:
public class MyGame : BaseGame
{
protected override void Initialize()
{
base.Initialize()
consolePrint("Initialized!");
}
}