EleCho.ScratchGame 0.2.1-alpha

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of EleCho.ScratchGame.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package EleCho.ScratchGame --version 0.2.1-alpha
NuGet\Install-Package EleCho.ScratchGame -Version 0.2.1-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EleCho.ScratchGame" Version="0.2.1-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EleCho.ScratchGame --version 0.2.1-alpha
#r "nuget: EleCho.ScratchGame, 0.2.1-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EleCho.ScratchGame as a Cake Addin
#addin nuget:?package=EleCho.ScratchGame&version=0.2.1-alpha&prerelease

// Install EleCho.ScratchGame as a Cake Tool
#tool nuget:?package=EleCho.ScratchGame&version=0.2.1-alpha&prerelease

EleCho.ScratchGame

一个小型的的, 基于 GDI+ 的 2D 游戏引擎. 点击查看预览视频

灵感来自于: MIT 的 Scratch

功能 / Features

  • 游戏对象
  • 鼠标与键盘
  • 游戏角色缩放与旋转

入门 / Get started

要进行游戏对象的逻辑更新, 你需要创建一个 Game 对象, 它用来承载所有的游戏对象(GameObject)

Game game = new Game();

接下来, 你可以向游戏中添加一个最简单的贴图:

Bitmap bmp;  // 假设这是我们要显示的贴图
game.AddSprite(new GameSprite()
{
    Sprite = bmp    // 为 GameSprite 赋贴图
});

为了在 WinForm 窗口中进行游戏渲染, 你需要一个 GamePanel, 将其拖动到窗口, 然后在指定其要渲染的游戏

void Load(object sender, EventArgs args)
{
    gamePanel.Game = game;    // 为 GamePanel 指定要渲染的游戏
}

要启动游戏逻辑更新循环以及渲染循环, 调用其方法即可:

game.StartGame();
gamePanel.StartRender();

使用 / Usage

自定义游戏对象

实现复杂的功能, 你必须使用定义自己的类型, 继承 GameSprite 或者 GameText, 并重写相关方法.

下面是一个不断向右移动的游戏对象定义:

class MoveRightForever : GameSprite
{
    public float Speed { get; set; } = 1f;
    public override void Update()
    {
        // SizeF 表示位移, 乘以 Game.DeltaTime 以使其速度不受帧率变化所影响
        Position += new SizeF(Speed, 0) * Game.DeltaTime;
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.2-alpha 90 5/11/2023
0.2.1-alpha 101 8/31/2022
0.1.1-alpha 111 8/29/2022
0.0.1-alpha 100 8/23/2022

为 GameSprite 添加了 Opacity