Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ArcadeMaker.Core/IGame.Funcs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,4 +1017,13 @@ IValue SetViewFollowingTarget(Exp.Instance? _, IValue?[] args)
/// <returns>The index of the currently activated room as a <see cref="NumberValue"/>.</returns>
[EngineFunc]
IValue GetRoomIndex(Exp.Instance? _, IValue?[] args) => Rooms.IndexOf(GetActivatedRoom().Model).ToExp();

/// <summary>
/// Takes screenshot from texture.
/// </summary>
/// <param name="_"></param>
/// <param name="args"></param>
/// <returns></returns>
[EngineFunc]
Exp.Void TakeScreenshot(Exp.Instance? _, IValue?[] args);
}
2 changes: 2 additions & 0 deletions src/ArcadeMaker.IDE/Debugging/FutileGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ public void SetCaption(string caption) { }
public Exp.Void ResumeSound(Exp.Instance? _, IValue?[] args) => Exp.Void.Return;

public Exp.Void ResumeAllSounds(Exp.Instance? _, IValue?[] args) => Exp.Void.Return;

public Exp.Void TakeScreenshot(Exp.Instance? _, IValue?[] args) => Exp.Void.Return;
}
36 changes: 34 additions & 2 deletions src/Engines/MonoGame/Core/ArcadeMakerMonoGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using MonoGame.Extended.ViewportAdapters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Pipes;
Expand Down Expand Up @@ -86,6 +87,9 @@ public RoomInstance? CurrentRoom
public TextureAtlas MainTextureAtlas { get; private set; }
public string MainTextureAtlasFilePath { get; set; }

private RenderTarget2D renderTarget = null;
private bool IsInsideDraw = false;

// runtime private data
private GameRunner<ArcadeMakerMonoGame> GameRunner { get; set; }
private RectangleF roomBounds;
Expand Down Expand Up @@ -182,6 +186,10 @@ protected override void Initialize()
LocalizationManager.SetCulture(selectedLanguage);

SpriteBatch = new SpriteBatch(GraphicsDevice);
renderTarget = new RenderTarget2D(
GraphicsDevice,
graphicsDeviceManager.PreferredBackBufferWidth,
graphicsDeviceManager.PreferredBackBufferHeight);

try
{
Expand Down Expand Up @@ -380,7 +388,21 @@ protected override void Draw(GameTime gameTime)
{
if (isOnError || CurrentRoom == null)
return;
IsInsideDraw = true;
try
{
DrawScene();
}
finally
{
IsInsideDraw = false;
}

base.Draw(gameTime);
}

private void DrawScene()
{
GraphicsDevice.Clear(backColor);

// if views are defined, we need to draw the room for each view, applying the corresponding camera transformations.
Expand Down Expand Up @@ -451,8 +473,6 @@ protected override void Draw(GameTime gameTime)

SpriteBatch.End();
}

base.Draw(gameTime);
}

public void DrawBackgrounds(int w, int h, Matrix transformMatrix)
Expand Down Expand Up @@ -744,6 +764,18 @@ public Exp.Void DrawEllipse(Exp.Instance? _, IValue?[] args)
return Exp.Void.Return;
}


public Exp.Void TakeScreenshot(Exp.Instance? _, IValue?[] args)
{
if(!IsInsideDraw)
throw new InvalidOperationException(
"TakeScreenshot must be called from inside Draw().");
GraphicsDevice.SetRenderTarget(renderTarget);
DrawScene();
GraphicsDevice.SetRenderTarget(null);
return Exp.Void.Return;
}

public (int x, int y) MousePositionInWindow
{
get
Expand Down