-
Notifications
You must be signed in to change notification settings - Fork 9
Getting Started
This will show how fast you can make a game with DartRocket.
Install Dart and an Editor. You have 4 options to do so:
-
The easiest way to get Dart is to download and install Dart+Editor. This is the recommended way, because Dart Editor free and gives excellent tooling support. Dart Editor also has a developer release, so you can get bleeding edge stuff easily. The only down side is the fact that the editor looks like eclipse. 😄
-
You can also use one of JetBrains IDE with Dart plugin or you can use Webstorm which has the Dart plugin already installed(although it's not free). In this case you need to specify the path to the Dart SDK, which can be easily done, because you can use the Dart Editor's built sdk or you can download the sdk.
-
Using the Chrome Dev Editor, which now is not the best solution, because it's still in developer preview, but I think it will be a really good option in the future.
-
Using Sublime Text with it's Dart plugin. Usually I only use it for viewing other's Dart code.
Create Web app
Create a Dart Web App and name it to mygame. You can easily be easily done in every option(except sublime text). Usually you can find the option in File->New Project. You will have an app with a html,css and dart file.
Adding Dependency
Adding DartRocket as dependency to pubsec.yaml. Instructions.
Clean up index.html
-
Delete everything in the dart file except the main method.
-
Delete the css file and it's reference in the html file.
-
Delete h1,div and p tags from the html file.
Start the game engine
-
Put
library mygame;at the beginning of the file. -
Import DartRocket in the main Dart file.
-
In the main method put
Game game = new Game();. This will start the engine.
Make a state
-
Lets make a new dart file called play.dart.
-
Lets make this file part of the mygame library by adding this to the file:
part of mygame;. -
In mygame.dart make play.dart part of the mygame library by adding this after the import:
part 'play.dart';. -
In play.dart lets make our class:
class Play extends State{}. This will give us an error. -
You must make a create() method. Tip: In Dart Editor you can quick fix the error using right mouse button on the error.
Adding and starting the state
-
In mygame.dart add the state to the StateManager:
game.stateManager.addState('play', new Play()); -
Start the play state:
game.stateManager.initState('play');
git clone https://github.com/StrykerKKD/dartrocket.git
After this, you can easily use the project template in the example folder.