介绍
在Godot中角色动画我们通常会使用AnimationPlayer这个节点去实现, 该节点支持关键帧


关于动画的一些注意事项
通常我们会让动画在运动帧开始, 然后在闲置帧结束,
如此一来 当玩家按下按钮时 不管时间有多短 都能看到明显的动画, 而不是你已经移动了 然而角色的脚却还没动
本文为作者原创转载时请注明出处 谢谢

乱码三千 – 码出一个新世界
当前素材库中只有一张小草地图片, 如下:

如何将其铺满整个背景, 得到如下效果:

我们可能第一时间会想到使用Tilemap, 不过手动绘制相对来说有些费时间, 在Godot中我们有更好的方法可以实现
使用Sprite+图片repeat的方式实现
首先创建一个Sprite节点
将草地图片添加至该节点的Texture属性上

启用Region属性

在纹理区域框选需要进行repeat的区域

选中草地文件 然后在导入面板开启重复功能, 最后点击重新导入

此时我们在纹理区域拉伸选框, 则可以对草地小图片进行重复并铺满整个背景

使用TextureRect+Tile实现
创建TextureRect节点
将图片拖拽至该节点的Texture属性上

Stretch Mode属性选择Tile

此时拉伸图片则自动重复

本文为作者原创转载时请注明出处 谢谢

xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua维护项目构建, 相当于是cmake的增强版, 其优点如下:
Make/Ninja 那样可以直接编译项目CMake/Meson 那样生成工程文件C/C++依赖库的集成使用问题C/C++进行混合编译Ninja持平编译宿主平台: MAC
交叉编译目标平台: Linux, Windows, IOS, Android ….
下载xmake
1 | bash <(curl -fsSL https://xmake.io/shget.text -k) |
测试c代码准备 文件取名为main
1 | #include <stdio.h> |
在源码目录下新建xmake.lua文件
并加入以下配置
1 | add_rules("mode.debug", "mode.release") |
编译前的环境准备好了,那接下来 咱们挨个来实现目标平台的可执行文件生成
下载xcode
直接应用市场下载
给xmake指定编译目标平台
1 | xmake f -p iphoneos |
编译程序
1 | xmake build main |
编译成功后 可以在build目录中找到对应的可执行文件

给xmake指定编译目标平台
1 | xmake f -p macosx |
编译程序
1 | xmake build main |
编译成功后 可以在build目录中找到对应的可执行文件

执行程序
由于编译宿主平台刚好是Mac 所以我们可以直接执行程序
1 | xmake run main |

下载mingw-w64
1 | brew install mingw-w64 |
给xmake指定编译目标平台
1 | xmake f -p mingw |
或者使用图形化界面配置
1 | xmake f --menu |

配置完后 我们查看xmake的配置显示当前平台为mingw:

编译程序
1 | xmake build main |
编译成功后 我们可以在build目录下找到生成的exe可执行文件:
关于mingw内部编译器
我们打印编译信息会发现mingw内部采用的是gcc编译工具

下载NDK
给xmake指定编译目标平台
1 | xmake f -p android --ndk=ndk路径 |
此时我们查看xmake配置显示当前编译平台为android:

编译程序
1 | xmake build main |
编译成功后 可以在编译目录查看到生成的可执行文件

重置配置
1 | xmake f -c |
指定交叉编译工具
1 | xmake f --toolchain=clang |
查看当前工程信息和xmake信息
1 | xmake show |
编译过程中查看完整的编译选项
1 | xmake -rv |
查看当前配置
1 | xmake config -v |

卸载xmake
1 | xmake update --uninstall |
交叉编译报错 unknown platform for xcode!
解决方案: 卸载xmake重装
本文为作者原创转载时请注明出处 谢谢

目前主流的平台有:
当C/C++程序写好后 如何快速在当前平台编译出各个平台的可执行文件
现在比较成熟的方案有:
docker容器编译cmake构建交叉编译环境docker容器编译基于GCC套件, 可实现对Android, Linux, Windows, Web平台的交叉编译, 详细介绍如下:
dockcross/base
Base image for other toolchain images. From Debian Jessie with GCC, make, autotools, CMake, Ninja, Git, and Python.
dockcross/android-arm
The Android NDK standalone toolchain for the arm architecture.
dockcross/android-arm64
The Android NDK standalone toolchain for the arm64 architecture.
dockcross/linux-arm64
Cross compiler for the 64-bit ARM platform on Linux, also known as AArch64.
dockcross/linux-armv5
Linux armv5 cross compiler toolchain for legacy devices like the Parrot AR Drone.
dockcross/linux-armv5-musl
Linux armv5 cross compiler toolchain using musl as base “libc”.
dockcross/linux-armv6
Linux ARMv6 cross compiler toolchain for the Raspberry Pi, etc.
dockcross/linux-armv7
Generic Linux armv7 cross compiler toolchain.
dockcross/linux-armv7a
Toolchain configured for ARMv7-A used in Beaglebone Black single board PC with TI SoC AM3358 on board, Cortex-A8.
dockcross/linux-mipsel
Linux mipsel cross compiler toolchain for little endian MIPS GNU systems.
dockcross/linux-mips
Linux mips cross compiler toolchain for big endian 32-bit hard float MIPS GNU systems.
dockcross/linux-s390x
Linux s390x cross compiler toolchain for S390X GNU systems.
dockcross/linux-ppc64le
Linux PowerPC 64 little endian cross compiler toolchain for the POWER8, etc. Important: Due to Issue #430, automatic build of newer images has been disabled.
dockcross/linux-x64
Linux x86_64 / amd64 compiler. Since the Docker image is natively x86_64, this is not actually a cross compiler.
dockcross/linux-x86
Linux i686 cross compiler.
dockcross/manylinux2014-x64
Docker manylinux2014 image for building Linux x86_64 / amd64 Python wheel packages. It includes Python 3.5, 3.6, 3.7, 3.8, and 3.9. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX2014 to “TRUE” in the toolchain.
dockcross/manylinux2014-x86
Docker manylinux2014 image for building Linux i686 Python wheel packages. It includes Python 3.5, 3.6, 3.7, 3.8, and 3.9. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX2014 to “TRUE” in the toolchain.
dockcross/manylinux2014-aarch64
Docker manylinux2014 image for building Linux aarch64 / arm64 Python wheel packages. It includes Python 3.5, 3.6, 3.7, 3.8, and 3.9. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX2014 to “TRUE” in the toolchain.
dockcross/manylinux2010-x64
Docker manylinux2010 image for building Linux x86_64 / amd64 Python wheel packages. It includes Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX2010 to “TRUE” in the toolchain.
dockcross/manylinux2010-x86
Docker manylinux2010 image for building Linux i686 Python wheel packages. It includes Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX2010 to “TRUE” in the toolchain.
dockcross/manylinux1-x64
Docker manylinux1 image for building Linux x86_64 / amd64 Python wheel packages. It includes Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8. Also has support for the dockcross script, and it has installations of CMake, Ninja, and scikit-build. For CMake, it sets MANYLINUX1 to “TRUE” in the toolchain.
dockcross/manylinux1-x86
Docker manylinux1 image for building Linux i686 Python wheel packages. It includes Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8. Also has support for the dockcross script, and it has installations of CMake, Ninja, and [ scikit-build](http:// scikit-build.org/). For CMake, it sets MANYLINUX1 to “TRUE” in the toolchain.
dockcross/web-wasm
The Emscripten WebAssembly/asm.js/JavaScript cross compiler.
dockcross/windows-static-x64
64-bit Windows cross-compiler based on MXE/MinGW-w64 with win32 threads and static linking.
dockcross/windows-static-x64-posix
64-bit Windows cross-compiler based on MXE/MinGW-w64 with posix threads and static linking.
dockcross/windows-static-x86
32-bit Windows cross-compiler based on MXE/MinGW-w64 with win32 threads and static linking.
dockcross/windows-shared-x64
64-bit Windows cross-compiler based on MXE/MinGW-w64 with win32 threads and dynamic linking.
dockcross/windows-shared-x64-posix
64-bit Windows cross-compiler based on MXE/MinGW-w64 with posix threads and dynamic linking.
dockcross/windows-shared-x86
32-bit Windows cross-compiler based on MXE/MinGW-w64 with win32 threads and dynamic linking.
具体使用可参见Github
cmake构建交叉编译环境首先我们需要下载cmake构建工具
然后下载用于交叉编译的套件
以Mac平台为例, 如果我需要编译各个平台的可执行文件, 那么首先需要下载能在Mac平台运行的目标平台编译包, 比如:
android平台:下载 Mac平台可运行的NDK (基于clang)
ios平台: 下载iphoneos SDK, xcode自带 我们只需下载xcode即可 (基于clang)
windows平台:下载MinGW 或者 MXE/MinGW-w64 (基于GCC)
Linux平台:如 arm/x86-Linux-gnueabi套件(基于GCC)
本文为作者原创转载时请注明出处 谢谢

在c/c++语言编译时 我们经常能碰到关于静态库(static)和动态库(shared)的链接
那它们有什么区别呢
静态库(static)是程序在编译期间进行链接的, 它会被打包进可执行程序当中
动态库(shared)也叫共享库, 它是在程序运行是进行链接的, 以独立的文件存在, 不会被打包进可执行程序中, 但是程序在执行时需要能找到这个库的具体位置, 否则程序可能出错
| 系统 | 动态库后缀 | 静态库后缀 |
|---|---|---|
| Linux | .so | .a |
| Mac | .dylib | .a |
| Windows | .dll | .lib |
优势:
劣势:
优势:
bug, 只需修复并重新编译库即可劣势:
静态库和动态库, 没有孰优孰劣一说, 具体看实际的应用场景, 每种库都有它的用武之地
本文为作者原创转载时请注明出处 谢谢

下载时提示SSL certificate problem:
1 | curl: (60) SSL certificate problem: certificate has expired |
原因:
这是证书认证缺失导致,可以在请求时关闭ssl证书认证
解决方案:
命令行中加上-k即可, 如:
1 | curl -fsSL https://xmake.io/shget.text -k |
本文为作者原创转载时请注明出处 谢谢

我们使用 Make 工具构建项目时,需要编写 Makefile,但不同的平台 Make工具是不一样的,比如Linux的GNU Make ,Windows 的 nmake,它们对 Makefile的规范也是不一样的,如果软件要跨平台,则需要针对每一种 Make工具写一份 Makefile,非常浪费时间
而且当软件比较庞大时,Makefile的编写也会变的复杂。
CMake(Cross-Platform-Make)是一个开源、跨平台的软件构建工具,它使用与平台独立的配置文件来对软件编译过程进行控制,根据用户所需,生成 Makefile 或者IDE的project。
编写CMake 配置文件CMakeLists.txt,一般放在项目的最顶层目录下
运行 cmake 命令,参数为 CMakeLists.txt 所在根路径,执行完成后得到 Makefile 文件。
使用make 命令进行编译。
1 | mkdir -p build && cd build |
指定最小版本
如果使用的 CMake版本低于该版本,则会发出致命错误
1 | cmake_minimum_required(VERSION 3.9) |
设置工程名 可以同时指定工程版本和语言,CXX代表C++
1 | project(sunflower VERSION 0.0.1 LANGUAGES C CXX) |
单行注释
1 | # 我是注释 |
多行注释
1 | #[[我是多行注释 |
设置 c/c++版本
1 | set(CMAKE_C_STANDARD 11) |
设置编译选项
1 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -w -O3") |
添加宏定义
1 | add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO) |
设置头文件搜索目录
实现编译时的 [-I] 选项,设置后引用头文件不需要使用相对路径,直接引用文件名
1 | include_directories( |
设置库文件搜索目录
实现编译时的[-L]选项,项目内部明确路径的库文件,可以通过该命令指定
1 | link_directories( |
查找指定库文件
查找到指定的预编译库,并将它的路径存储在变量中。
默认的搜索路径为 cmake 包含的系统库,因此如果是NDK的公共库只需要指定库的name 即可(不需path),类似的命令还有find_file()、find_path()、find_program()、find_package()
1 | find_library(log-lib,log) |
查找指定目录下源文件
获取指定目录下源文件列表,保存到 DIR_SRCS 变量中,后续编译构建目标可执行文件
注意这里不能递归获取子目录下的源文件
1 | aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRCS) |
添加子目录源文件
使用命令 add_subdirectory 指明本项目包含一个子目录,这样子目录下的 CMakeLists.txt文件和源文件也会被处理。
项目包含多个子目录时,通常可以在子目录下也定义CMakeLists.txt 文件,并通过 add_library 生成包含子目录源码的库文件,并最终链接到目标可执行文件
1 | add_subdirectory(utils) |
递归查找目录下的所有源文件
可以通过 file命令递归获取指定目录下的所有源文件,这样可以不用为子目录专门定义CMakeLists.txt,也不需要通过链接的方式集成各个子目录,而是统一编译构建
1 | file(GLOB_RECURSE DIR_SRCS |
设置可执行文件输出路径
1 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) |
生成可执行文件
1 | add_executable(${PROJECT_NAME} ${DIR_SRCS}) |
生成库文件
1 | add_library(${PROJECT_NAME} STATIC ${DIR_SRCS}) |
链接库文件
1 | set(EXTRA_LIBS |
1 | PROJECT_SOURCE_DIR:工程的根目录 |
使用SET, 比如:
1 | set(BINARY_NAME "juce_jni") |
设置不同版本的编译选项
1 | set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") |
cmake 时指定版本
1 | cmake .. -DCMAKE_BUILD_TYPE=Debug |
1 | +-- CMakeTest |
1 | cmake_minimum_required(VERSION 3.7.1) |
本文转载自: CSDN
