This is the Ruby 2D gem. Check out the Ruby 2D website to learn how to get started building 2D apps in Ruby.
To work on the gem locally, first clone this repo using:
git clone --recursive https://github.com/ruby2d/ruby2d.git
To keep the size of this repository small, Git submodules are used to reference test media and other assets. The --recursive
flag ensures submodules are initialized and updated when this repo is cloned. If you happened to clone this repo without the --recursive
flag, you can still initialize and update submodules with:
git submodule init
git submodule update --remote
Update these submodules at any time using git submodule update --remote
or the rake update
task.
Next, install dependencies:
bundle install
to get the required development gems.brew install mruby
. On Ubuntu, use sudo apt install mruby libmruby-dev
Finally, run rake
to build and install the gem locally. Use rake dev
to build referencing user-installed libraries (e.g. SDL).
Ruby 2D uses a combination of automated tests via RSpec and manual, interactive tests to verify the correctness of visual, audio, and input functionality. Build the gem and run all automated tests using the rake
command. Build and run an interactive test in the test/
directory using rake test:<environment> <name_of_test>
, for example:
# Run `test/testcard.rb` using the standard Ruby interpreter, MRI (CRuby)
rake test:int testcard
# Build `test/audio.rb` natively using MRuby and run
rake test:native audio
# Build `test/mouse.rb` for the web using WebAssembly and run in the default browser
rake test:web mouse
Ruby 2D is an entirely open-source project (including its dependencies) built by dedicated folks who believe creating 2D applications should be simple, natural, and joyful, in the spirit of the Ruby language itself.
If you'd like to get involved, there are a number of ways to do so:
Suggest and implement new features.
Add support for more platforms.
Find and fix issues.
Write and review documentation.
Create and improve examples.
In order to achieve such simplicity, a lot has to happen under the hood. Whether adding a feature or fixing a bug, try to do the following to ensure your pull request gets merged. Some of these might seem daunting, but we're happy to help along the way!
Check if there is an existing issue, and if not, open a new one to start a discussion. Before dedicating time and energy to an idea or fix, let's make sure it's consistent with the principles and goals of the project, and that we have a solid strategy in place to implement and test.
Use a subset of Ruby that works everywhere. Ruby 2D applications are, of course, written in Ruby. Some users may choose to harness the full power of the language, standard library, and ecosystem of gems by writing interpreted apps targeting the standard implementation, MRI. Others may want to target the web via WebAssembly, mobile devices, or build native desktop applications, all which make use of a different Ruby implementation called MRuby. Ruby 2D aims to support all of these use cases, even with the same app codebase. Your contribution must support a subset of Ruby that is compatible with and behaves similarly across MRI and MRuby. Beyond reading the documentation for each Ruby implementation, you can also try out code snippets on the command line using their respective REPLs: irb
for MRI, and mirb
for MRuby.
Comprehensively test your change. Unlike other Ruby libraries, not everything here can be easily covered with unit tests alone. We also need to make sure things look and sound right, inputs work as expected, and behavior is consistent across all platforms Ruby 2D supports.
rake update
to update the submodulesversion.rb
, commit changesv#.#.#
, and write a little release noterake
to build the gem, then push it to rubygems.org with gem push ruby2d-#.#.#.gem
前言 过于简单,官方有详细教程:Ruby’s Adventure:2D 主要看看发射子弹和范围伤害的实现。 自动消失的对话框 这个是显示一段时间直接消失,不如之前看的另一个项目中的渐变消失效果 【Creator Kit - RPG 代码分析】(3)-游戏玩法-消息提示、音频管理、输入控制、角色控制器 public class NonPlayerCharacter : MonoBehaviour {
第一种,采用更加现实的模式进行运动,代码里含有加速度和速度,以及摩擦力,在人物开始运动时会有一定延迟(毕竟要先加速嘛),优点时贴合实际,这套模式可采用到赛车游戏等需要加速的游戏中。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyRubyController