add samples
This commit is contained in:
parent
5a4279c15c
commit
70a5aff6e9
|
|
@ -1,12 +1,13 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.271
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "HelloWorld\HelloWorld.vcxproj", "{3561A359-F9FD-48AB-A977-34E7E568BC8E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Samples", "Samples\Samples.vcxproj", "{45F5738D-CDF2-4024-974D-25B64F9043DE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
|
|
@ -15,6 +16,14 @@ Global
|
|||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|x64.Build.0 = Debug|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.Build.0 = Release|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|x64.ActiveCfg = Release|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|x64.Build.0 = Release|x64
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.Deploy.0 = Debug|Win32
|
||||
|
|
@ -25,14 +34,14 @@ Global
|
|||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|Win32.Build.0 = Release|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.ActiveCfg = Release|x64
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.Build.0 = Release|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|x64.Build.0 = Debug|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.Build.0 = Release|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|x64.ActiveCfg = Release|x64
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|x64.Build.0 = Release|x64
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|x64.Build.0 = Debug|x64
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|Win32.Build.0 = Release|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|x64.ActiveCfg = Release|x64
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
class Demo1
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo1;
|
||||
}
|
||||
|
||||
Demo1()
|
||||
{
|
||||
// 创建文本
|
||||
auto text = E_NEW Text(L"Hello Easy2D!");
|
||||
// 让文本显示在屏幕中央
|
||||
text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
||||
text->SetAnchor(0.5, 0.5);
|
||||
// 添加到场景
|
||||
this->AddChild(text);
|
||||
|
||||
// 执行动画
|
||||
text->AddAction(
|
||||
Tween::Spawn({ // Action5: 同时执行 Action1 和 Action4, 并无限循环
|
||||
Tween::RotateBy(60).SetDuration(1000), // Action1: 1秒旋转 60 度
|
||||
Tween::Sequence({ // Action4: 顺序执行 Action2 和 Action3
|
||||
Tween::FadeOut(500), // Action2: 500毫秒淡出动画
|
||||
Tween::FadeIn(500) // Action3: 500毫秒淡入动画
|
||||
})
|
||||
}).SetLoopCount(-1)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
class Man
|
||||
: public Sprite
|
||||
{
|
||||
public:
|
||||
Man()
|
||||
{
|
||||
// 加载图片
|
||||
Load(L"res/man.png");
|
||||
// 缩小图片
|
||||
SetScale(0.5f);
|
||||
}
|
||||
|
||||
// 每帧更新时
|
||||
void OnUpdate(Duration dt) override
|
||||
{
|
||||
// 获取输入设备
|
||||
auto input = Input::Instance();
|
||||
// 按下左右键
|
||||
if (input->IsDown(KeyCode::Left))
|
||||
{
|
||||
this->Move(-2, 0);
|
||||
}
|
||||
else if (input->IsDown(KeyCode::Right))
|
||||
{
|
||||
this->Move(2, 0);
|
||||
}
|
||||
|
||||
// 按下上下键
|
||||
if (input->IsDown(KeyCode::Up))
|
||||
{
|
||||
this->Move(0, -2);
|
||||
}
|
||||
else if (input->IsDown(KeyCode::Down))
|
||||
{
|
||||
this->Move(0, 2);
|
||||
}
|
||||
|
||||
// 按下鼠标左键,顺时针旋转小人
|
||||
if (input->IsDown(MouseButton::Left))
|
||||
{
|
||||
// 获取当前旋转角度
|
||||
float rotation = this->GetRotation();
|
||||
// 设置角度值+2
|
||||
this->SetRotation(rotation + 2);
|
||||
}
|
||||
|
||||
// 点击鼠标右键,隐藏或显示小人
|
||||
if (input->WasPressed(MouseButton::Right))
|
||||
{
|
||||
// 获取当前显示状态
|
||||
bool visible = this->IsVisible();
|
||||
// 设置相反的显示状态
|
||||
this->SetVisible(!visible);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Demo2
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo2;
|
||||
}
|
||||
|
||||
Demo2()
|
||||
{
|
||||
// 创建人物
|
||||
auto man = E_NEW Man;
|
||||
// 在屏幕上居中显示
|
||||
man->SetAnchor(0.5f, 0.5f);
|
||||
man->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
||||
|
||||
// 创建说明文字
|
||||
auto text = E_NEW Text(L"按上下左右键移动\n按鼠标左键旋转\n点击鼠标右键隐藏");
|
||||
// 设置文字位置
|
||||
text->SetAnchor(0.5f, 0.5f);
|
||||
text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT - 50);
|
||||
text->SetAlignment(TextAlign::Center);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(man);
|
||||
this->AddChild(text);
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
class Demo3
|
||||
: public Scene
|
||||
{
|
||||
MusicPtr music; // 音乐对象
|
||||
TextPtr volume_text; // 音量文字
|
||||
TextPtr state_text; // 播放状态文字
|
||||
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo3;
|
||||
}
|
||||
|
||||
Demo3()
|
||||
{
|
||||
// 加载音乐
|
||||
music = E_NEW Music;
|
||||
if (!music->Load(L"res/music.wav"))
|
||||
{
|
||||
music = nullptr;
|
||||
|
||||
auto err = E_NEW Text(L"音频文件加载失败");
|
||||
this->AddChild(err);
|
||||
}
|
||||
|
||||
// 播放音乐(参数用来设置播放循环次数,-1 表示循环播放)
|
||||
music->Play(-1);
|
||||
|
||||
// 创建说明文字
|
||||
auto intro_text = E_NEW Text(L"按上下键调整音量\n按空格键暂停或继续");
|
||||
intro_text->SetAnchor(0.5f, 0.5f);
|
||||
intro_text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 - 50);
|
||||
|
||||
// 创建音量文字
|
||||
volume_text = E_NEW Text(L"当前音量:");
|
||||
volume_text->SetAnchor(0.5f, 0.5f);
|
||||
volume_text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + 30);
|
||||
|
||||
// 创建状态文字
|
||||
state_text = E_NEW Text(L"当前状态:");
|
||||
state_text->SetAnchor(0.5f, 0.5f);
|
||||
state_text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + 60);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(intro_text);
|
||||
this->AddChild(volume_text);
|
||||
this->AddChild(state_text);
|
||||
}
|
||||
|
||||
void OnUpdate(Duration dt) override
|
||||
{
|
||||
if (music == nullptr)
|
||||
return;
|
||||
|
||||
// 获取音量和播放状态
|
||||
float volume = music->GetVolume();
|
||||
bool playing = music->IsPlaying();
|
||||
|
||||
// 修改文本
|
||||
volume_text->SetText(L"当前音量:" + std::to_wstring(volume));
|
||||
state_text->SetText(playing ? L"当前状态:正在播放" : L"当前状态:停止播放");
|
||||
|
||||
// 获取输入设备
|
||||
auto input = Input::Instance();
|
||||
|
||||
// 按空格键暂停或继续
|
||||
if (input->WasPressed(KeyCode::Space))
|
||||
{
|
||||
music->IsPlaying() ? music->Pause() : music->Resume();
|
||||
}
|
||||
|
||||
// 按上下键调整音量
|
||||
if (input->WasPressed(KeyCode::Up))
|
||||
{
|
||||
music->SetVolume(volume + 0.1f);
|
||||
}
|
||||
else if (input->WasPressed(KeyCode::Down))
|
||||
{
|
||||
music->SetVolume(volume - 0.1f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{45F5738D-CDF2-4024-974D-25B64F9043DE}</ProjectGuid>
|
||||
<RootNamespace>Samples</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="common.h" />
|
||||
<ClInclude Include="Demo1.h" />
|
||||
<ClInclude Include="Demo2.h" />
|
||||
<ClInclude Include="Demo3.h" />
|
||||
<ClInclude Include="include-forwards.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Easy2D\Easy2D.vcxproj">
|
||||
<Project>{ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include-forwards.h" />
|
||||
<ClInclude Include="Demo1.h" />
|
||||
<ClInclude Include="common.h" />
|
||||
<ClInclude Include="Demo2.h" />
|
||||
<ClInclude Include="Demo3.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "easy2d.h"
|
||||
|
||||
using namespace easy2d;
|
||||
|
||||
const int WINDOW_WIDTH = 640;
|
||||
const int WINDOW_HEIGHT = 480;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include "Demo1.h"
|
||||
#include "Demo2.h"
|
||||
#include "Demo3.h"
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "include-forwards.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Demo
|
||||
{
|
||||
String title;
|
||||
ScenePtr(*Create)();
|
||||
};
|
||||
|
||||
Demo s_Demos[] = {
|
||||
{ L"动画示例", Demo1::Create },
|
||||
{ L"输入示例", Demo2::Create },
|
||||
{ L"音频播放示例", Demo3::Create },
|
||||
};
|
||||
int s_DemoIndex = 0;
|
||||
int s_DemoNum = sizeof(s_Demos) / sizeof(Demo);
|
||||
}
|
||||
|
||||
class DemoApp
|
||||
: public Application
|
||||
{
|
||||
public:
|
||||
DemoApp()
|
||||
{
|
||||
Options options;
|
||||
options.title = L"Easy2D示例程序";
|
||||
options.width = WINDOW_WIDTH;
|
||||
options.height = WINDOW_HEIGHT;
|
||||
|
||||
Init(options);
|
||||
}
|
||||
|
||||
void OnStart() override
|
||||
{
|
||||
ChangeDemoScene();
|
||||
}
|
||||
|
||||
void ChangeDemoScene()
|
||||
{
|
||||
Window::Instance()->SetTitle(s_Demos[s_DemoIndex].title);
|
||||
|
||||
ScenePtr scene = s_Demos[s_DemoIndex].Create();
|
||||
EnterScene(scene);
|
||||
|
||||
// 添加按键监听
|
||||
scene->AddListener(KeyboardEvent::Up, Closure(this, &DemoApp::KeyPressed));
|
||||
|
||||
// 显示提示文字
|
||||
TextPtr intro = new Text(L"Key 1~3 to select demo");
|
||||
intro->SetFontSize(16.f);
|
||||
scene->AddChild(intro);
|
||||
}
|
||||
|
||||
void KeyPressed(Event const& evt)
|
||||
{
|
||||
E2D_ASSERT(evt.type == KeyboardEvent::Up);
|
||||
|
||||
if (evt.key.code > KeyCode::Num0 &&
|
||||
evt.key.code <= (KeyCode::Num0 + s_DemoNum))
|
||||
{
|
||||
s_DemoIndex = evt.key.code - KeyCode::Num1;
|
||||
ChangeDemoScene();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
DemoApp app;
|
||||
app.Run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
::MessageBoxA(nullptr, e.what(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 702 KiB |
Binary file not shown.
|
|
@ -154,6 +154,13 @@ namespace easy2d
|
|||
Window::Instance()->Destroy();
|
||||
}
|
||||
|
||||
void Application::Destroy()
|
||||
{
|
||||
transition_ = nullptr;
|
||||
next_scene_ = nullptr;
|
||||
curr_scene_ = nullptr;
|
||||
}
|
||||
|
||||
void Application::EnterScene(ScenePtr const & scene)
|
||||
{
|
||||
E2D_ASSERT(scene && "Application::EnterScene failed, NULL pointer exception");
|
||||
|
|
@ -218,6 +225,8 @@ namespace easy2d
|
|||
next_scene_ = nullptr;
|
||||
}
|
||||
|
||||
OnUpdate(dt);
|
||||
|
||||
if (curr_scene_)
|
||||
curr_scene_->Update(dt);
|
||||
|
||||
|
|
@ -284,7 +293,7 @@ namespace easy2d
|
|||
if (!app->transition_ && app->curr_scene_)
|
||||
{
|
||||
Event evt((msg == WM_KEYDOWN) ? KeyboardEvent::Down : KeyboardEvent::Up);
|
||||
evt.key.code = KeyCode(wparam);
|
||||
evt.key.code = static_cast<int>(wparam);
|
||||
evt.key.count = static_cast<int>(lparam & 0xFF);
|
||||
|
||||
app->curr_scene_->Dispatch(evt);
|
||||
|
|
|
|||
|
|
@ -74,12 +74,18 @@ namespace easy2d
|
|||
// 销毁时
|
||||
virtual void OnDestroy() {}
|
||||
|
||||
// 更新时
|
||||
virtual void OnUpdate(Duration dt) { E2D_NOT_USED(dt); }
|
||||
|
||||
// 运行
|
||||
void Run();
|
||||
|
||||
// 结束
|
||||
void Quit();
|
||||
|
||||
// 销毁
|
||||
void Destroy();
|
||||
|
||||
// 切换场景
|
||||
void EnterScene(
|
||||
ScenePtr const& scene /* 场景 */
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace easy2d
|
|||
|
||||
struct
|
||||
{
|
||||
MouseButton button; // 仅当消息类型为 Down | Up | Click 时有效
|
||||
int button; // 仅当消息类型为 Down | Up | Click 时有效
|
||||
};
|
||||
|
||||
struct
|
||||
|
|
@ -79,7 +79,7 @@ namespace easy2d
|
|||
Last
|
||||
};
|
||||
|
||||
KeyCode code;
|
||||
int code; // enum KeyCode
|
||||
int count;
|
||||
|
||||
static inline bool Check(UINT type)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace easy2d
|
|||
public:
|
||||
Font(
|
||||
const String& family = L"",
|
||||
float size = 22,
|
||||
float size = 18,
|
||||
unsigned int weight = FontWeight::Normal,
|
||||
bool italic = false
|
||||
)
|
||||
|
|
|
|||
|
|
@ -72,34 +72,22 @@ namespace easy2d
|
|||
want_update_ = true;
|
||||
}
|
||||
|
||||
bool Input::IsDown(KeyCode code)
|
||||
bool Input::IsDown(int code_or_btn)
|
||||
{
|
||||
return keys_[static_cast<int>(code)];
|
||||
E2D_ASSERT(code_or_btn >= 0 && code_or_btn < 256);
|
||||
return keys_[code_or_btn];
|
||||
}
|
||||
|
||||
bool Input::IsDown(MouseButton btn)
|
||||
bool Input::WasPressed(int code_or_btn)
|
||||
{
|
||||
return keys_[static_cast<int>(btn)];
|
||||
E2D_ASSERT(code_or_btn >= 0 && code_or_btn < 256);
|
||||
return keys_pressed_[code_or_btn];
|
||||
}
|
||||
|
||||
bool Input::WasPressed(KeyCode code)
|
||||
bool Input::WasReleased(int code_or_btn)
|
||||
{
|
||||
return keys_pressed_[static_cast<int>(code)];
|
||||
}
|
||||
|
||||
bool Input::WasPressed(MouseButton btn)
|
||||
{
|
||||
return keys_pressed_[static_cast<int>(btn)];
|
||||
}
|
||||
|
||||
bool Input::WasReleased(KeyCode code)
|
||||
{
|
||||
return keys_released_[static_cast<int>(code)];
|
||||
}
|
||||
|
||||
bool Input::WasReleased(MouseButton btn)
|
||||
{
|
||||
return keys_released_[static_cast<int>(btn)];
|
||||
E2D_ASSERT(code_or_btn >= 0 && code_or_btn < 256);
|
||||
return keys_released_[code_or_btn];
|
||||
}
|
||||
|
||||
float Input::GetMouseX()
|
||||
|
|
|
|||
|
|
@ -31,34 +31,19 @@ namespace easy2d
|
|||
E2D_DECLARE_SINGLETON(Input);
|
||||
|
||||
public:
|
||||
// 检测键盘按键是否正被按下
|
||||
// 检测键盘或鼠标按键是否正被按下
|
||||
bool IsDown(
|
||||
KeyCode code
|
||||
int code_or_btn
|
||||
);
|
||||
|
||||
// 检测鼠标按键是否正被按下
|
||||
bool IsDown(
|
||||
MouseButton btn
|
||||
);
|
||||
|
||||
// 检测键盘按键是否刚被点击
|
||||
// 检测键盘或鼠标按键是否刚被点击
|
||||
bool WasPressed(
|
||||
KeyCode code
|
||||
int code_or_btn
|
||||
);
|
||||
|
||||
// 检测鼠标按键是否刚被点击
|
||||
bool WasPressed(
|
||||
MouseButton btn
|
||||
);
|
||||
|
||||
// 检测键盘按键是否刚抬起
|
||||
// 检测键盘或鼠标按键是否刚抬起
|
||||
bool WasReleased(
|
||||
KeyCode code
|
||||
);
|
||||
|
||||
// 检测鼠标按键是否刚抬起
|
||||
bool WasReleased(
|
||||
MouseButton btn
|
||||
int code_or_btn
|
||||
);
|
||||
|
||||
// 資誼報炎 x 恫炎
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ namespace easy2d
|
|||
String const& family
|
||||
);
|
||||
|
||||
// 设置字号(默认值为 22)
|
||||
// 设置字号(默认值为 18)
|
||||
void SetFontSize(
|
||||
float size
|
||||
);
|
||||
|
|
|
|||
|
|
@ -24,88 +24,98 @@
|
|||
namespace easy2d
|
||||
{
|
||||
// 報炎梓囚
|
||||
enum class MouseButton : int
|
||||
struct MouseButton
|
||||
{
|
||||
Left = VK_LBUTTON, // 報炎恣囚
|
||||
Right = VK_RBUTTON, // 報炎嘔囚
|
||||
Middle = VK_MBUTTON // 報炎嶄囚
|
||||
typedef int Value;
|
||||
|
||||
enum : int
|
||||
{
|
||||
Left = VK_LBUTTON, // 報炎恣囚
|
||||
Right = VK_RBUTTON, // 報炎嘔囚
|
||||
Middle = VK_MBUTTON // 報炎嶄囚
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// 梓囚囚峙
|
||||
enum class KeyCode : int
|
||||
struct KeyCode
|
||||
{
|
||||
Unknown = 0,
|
||||
Up = VK_UP,
|
||||
Left = VK_LEFT,
|
||||
Right = VK_RIGHT,
|
||||
Down = VK_DOWN,
|
||||
Enter = VK_RETURN,
|
||||
Space = VK_SPACE,
|
||||
Esc = VK_ESCAPE,
|
||||
Ctrl = VK_CONTROL,
|
||||
Shift = VK_SHIFT,
|
||||
typedef int Value;
|
||||
|
||||
A = 0x41,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
E,
|
||||
F,
|
||||
G,
|
||||
H,
|
||||
I,
|
||||
J,
|
||||
K,
|
||||
L,
|
||||
M,
|
||||
N,
|
||||
O,
|
||||
P,
|
||||
Q,
|
||||
R,
|
||||
S,
|
||||
T,
|
||||
U,
|
||||
V,
|
||||
W,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
enum : int
|
||||
{
|
||||
Unknown = 0,
|
||||
Up = VK_UP,
|
||||
Left = VK_LEFT,
|
||||
Right = VK_RIGHT,
|
||||
Down = VK_DOWN,
|
||||
Enter = VK_RETURN,
|
||||
Space = VK_SPACE,
|
||||
Esc = VK_ESCAPE,
|
||||
Ctrl = VK_CONTROL,
|
||||
Shift = VK_SHIFT,
|
||||
|
||||
Num0 = 0x30,
|
||||
Num1,
|
||||
Num2,
|
||||
Num3,
|
||||
Num4,
|
||||
Num5,
|
||||
Num6,
|
||||
Num7,
|
||||
Num8,
|
||||
Num9,
|
||||
A = 0x41,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
E,
|
||||
F,
|
||||
G,
|
||||
H,
|
||||
I,
|
||||
J,
|
||||
K,
|
||||
L,
|
||||
M,
|
||||
N,
|
||||
O,
|
||||
P,
|
||||
Q,
|
||||
R,
|
||||
S,
|
||||
T,
|
||||
U,
|
||||
V,
|
||||
W,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
|
||||
Numpad0 = VK_NUMPAD0,
|
||||
Numpad1,
|
||||
Numpad2,
|
||||
Numpad3,
|
||||
Numpad4,
|
||||
Numpad5,
|
||||
Numpad6,
|
||||
Numpad7,
|
||||
Numpad8,
|
||||
Numpad9,
|
||||
Num0 = 0x30,
|
||||
Num1,
|
||||
Num2,
|
||||
Num3,
|
||||
Num4,
|
||||
Num5,
|
||||
Num6,
|
||||
Num7,
|
||||
Num8,
|
||||
Num9,
|
||||
|
||||
F1 = VK_F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
Numpad0 = VK_NUMPAD0,
|
||||
Numpad1,
|
||||
Numpad2,
|
||||
Numpad3,
|
||||
Numpad4,
|
||||
Numpad5,
|
||||
Numpad6,
|
||||
Numpad7,
|
||||
Numpad8,
|
||||
Numpad9,
|
||||
|
||||
F1 = VK_F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue