Creation of a game with Citrus Engine

As said, we’re going to create a little game with Citrus Engine.

Since the engine it’s ready, we can start with level design.

So let’s open the Citrus Engine Level Architect, included in the package, and let’s start playing with it.

The key of this little tool is the right mouse key. Pressing it will open a menu with all available assets.

Choose Platform and you will be able to create static Box2D boxes.

Now click anywhere with left mouse button and a black square will appear: that’s the platform. Drag and adjust it as you want.

Don’t worry about extreme precision: we’ll retouch it later. Once you placed some platforms, from the right click menu choose and place the hero, a coin and a couple of crates. Crates represent dynamic Box2D objects. This is what I’ve made:

Then select File->Save Level As and save your level. Don’t worry about the path: despite what suggesting in the official docs we won’t include external XML files. We are making a game to distribute it, so we need a single file.

Edit the created XML file removing this line

and eventually rounding the x, y, width and height attributes of your assets.

This is my final XML:


	
	
	
	
	
	
	
	

Then drop a few AS3 lines:

package {
	import flash.display.MovieClip;
	import com.citrusengine.core.CitrusEngine;
	import com.blueflamedev.math.*;
	public class citrusdemo extends MovieClip {
		public function citrusdemo() {
			var level_xml:XML =
			
			  
			  
			  
			  
			  
			  
			  
			  
			;
			var ce:CitrusEngine=CitrusEngine.getInstance();
			ce.initialize(this);
			ce.camera.debugDraw=true;
			ce.physics.gravity=new MathVector(0,900);
			ce.loop.run(this);
			ce.manager.createSet("Level 1",XML(level_xml));
		}
	}
}

Lines 7-17: Importing the XML

Lines 18-19: Initializing the engine

Line 20: Turning on debug draw

Line 21: Defining the gravity. I found MathVector(0,900) very similar to b2Vec(0,10)

Line 22: Starting the simulation

Line 23: Loading the XML level

And that’s it:

Move your hero with arrow keys and jump with spacebar. Try to get the coin.

Download the source code.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers