All posts by Aymeric

About Aymeric

Freelance Interactive & Game Developer.

Take photo with AIR on iOS

Hey guys,

Recently, I’ve worked on a mobile project and camera use drives me crazy about performances. On iOS, after taking a photo and validate it, it freezes the application during one minute to be able to encode it.
I’ve made lots of tests with several libraries, using Alchemy ones, and finally the fastest way (less than 5 seconds) is to use the new BitmapData encode method, available since Flash Player 11.3 and AIR 3.3.

Here is the code (lots of code come from this excellent post) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
if (CameraUI.isSupported) {
	viewsAC.addItem({label:"Take Photo", icon:cameraIcon});
	myCam = new CameraUI();
	myCam.addEventListener(MediaEvent.COMPLETE, onCameraComplete);
}
 
protected function onCameraComplete(evt:MediaEvent):void
{
	sqlStatement = new SQLStatement();
	sqlStatement.sqlConnection = model2.connection;
	sqlStatement.text =
		"INSERT INTO albumItems (album, photoFile, dateAdded) " +
		"VALUES (:album, :photoFile, :dateAdded)";
	sqlStatement.parameters[":album"] = model2.selectedAlbum;
 
	var mediaPromise:MediaPromise = evt.data;
	if (mediaPromise.file == null) {
 
		// For iOS we need to load with a Loader first
		_loader = new Loader();
		_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageloader_complete, false, 0, true);
		_loader.loadFilePromise(mediaPromise);
 
		return;
	} else {
 
		// Android & BlackBerry
		registerPhoto(mediaPromise.file.url)
	}
}
 
private function imageloader_complete(event:Event):void {
 
	_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, imageloader_complete);
 
	var loaderInfo:LoaderInfo = event.target as LoaderInfo;
 
	if (CameraRoll.supportsAddBitmapData) {
 
		var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height);
		bitmapData.draw(loaderInfo.loader);
		var file:File = File.applicationStorageDirectory.resolvePath("image" + new Date().time + ".jpg");
		var stream:FileStream = new FileStream()
		stream.open(file, FileMode.WRITE);
		var bytes:ByteArray = bitmapData.encode(bitmapData.rect, new flash.display.JPEGEncoderOptions());
		stream.writeBytes(bytes, 0, bytes.bytesAvailable);
		stream.close();
 
	}
	registerPhoto(file.url)
 
}
 
private function registerPhoto(url:String):void {
 
	sqlStatement.parameters[":photoFile"] = url;
 
	sqlStatement.parameters[":dateAdded"] = new Date();
	sqlStatement.execute();
 
	viewsList.selectedIndex = -1;
}

Becoming a freelancer

Hi! Since the new Citrus Engine website, this blog was in stand-by during the last two months. This year I worked really hard, using my personnal time, on the Citrus Engine which is the most advanced Open-Source & free AS3 game engine. This work and its support aren’t finished.

Now I’m happy to share with you some exciting news: in January, I will start my career as a freelancer! Thanks to this status, I will be able to work with companies on strong games using the Citrus Engine and make it even more professional. Take a look on its support page.

Will I only make games using this engine? No, diversity is stimulating. I’ve just bought an iMac to be able to re-do some Objective-C, and develop on iOS using Haxe NME.

To sum-up, I will focus on games, mobile applications, and maybe some websites using AS3, Haxe, Objective-C, HTML5 and PHP programming languages. In a long run I hope to improve my Unity3D knowledge, and in a short period I will give Cocos2D a try.

Also I will try to keep this blog alive, making one article by month which won’t be related to the Citrus Engine.

Future is exciting. Feel free to contact me!

Citrus Engine V3 and a new website!

Hey there,

I’m glad to announce the V3 release and a new website for the Citrus Engine! It has been a long and hard work. Most of the new tutorials and news will be displayed on this new website. Don’t know how I will manage this blog on Citrus Engine subject due to the new website, I will certainly replicate some contents.

Anyway I let you explore the new website 🙂 Don’t hesitate to give some feedback.

Playing with Cadet Editor 3D and AwayPhysics

The 3D part is a bit in stand-by this last weeks on the Citrus Engine, because I’m polishing the engine for the V3 which should be out this week!

I’ve never clearly introduced AwayPhysics in the Citrus Engine, so it’s the day! The idea is to have a similar pre-built platformer objects that we already have with Box2D and Nape but with AwayPhysics this time for 3D stuff! This work and Away3D support will evolve during the V3.

Now that 3D views and physics are supported, it’s time to give a look on which tool we can use as a 3D game Level Editor. At first, I thought to Prefab. This is the best tool to create a scene with Away3D, importing assets, add lights… But too complex for a simple level design, I mean : hey the Citrus Engine is not a concurrent to Unity3D (which I started to learn thanks to this awesome tutorial) 😀 Its 3D physics part is just here to create basic 3D game / puzzle. Also the level editor has to support object creation (physics object), this isn’t obvious with Prefab.
Then I gave a look to Cadet Editor, the 3D editor is very easy to handle. You can create quickly sphere, cube and plane objects, add lights… That’s the right tool to see what can be done!

Continue reading Playing with Cadet Editor 3D and AwayPhysics

Create combination of physics objects in Citrus Engine

Some days ago, I said that November will be an awesome month for the Citrus Engine. So what is coming?

We’re the 2nd, November is already here and something huge is already happened to the CE : a tutorial on gotoandlearn made by Lee Brimelow, an Adobe Game Developer Evangelist! Definitely, an excellent tutorial to get start with the Citrus Engine. There’ll be other tutorials later, a new website and the forum’ll move on Starling website. Most of the future game will use Starling so that’s a good move! We’re not forgetting the 3D part, don’t worry 😉

Everything should be ready for the next Adobe Game Jam in Chicago. So that’s the plan. Now let’s go for a small tutorial.

Continue reading Create combination of physics objects in Citrus Engine

Create a game like Tiny Wings

Tiny Wings is really a cute game and very fun to play thanks to physics content! It uses Box2D. If you’ve never played the game, give it a quick look :

Generate those type of hills with a physics engine is complicated for a novice. You’ll find cool tutorials on Emanuele Feronato’s website using Box2D and an other on Lorenzo Nuvoletta’s website using Nape.

Someone asks me if it was possible to create this type of game with the Citrus Engine, absolutely! So let’s go for a quick tutorial.

Continue reading Create a game like Tiny Wings

Moved from Box2D Alchemy to Box2D AS3

In the Citrus Engine, people knows that I’m very attached to the Box2D Alchemy version. Thanks to Alchemy we should have better performance than the pure AS3 version. Also this Alchemy version had some cool features mostly on the way you could manage collision : you don’t use a gobal contact listener like in any Box2D version, you use something very closer to AS3 event management. Example :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
override protected function createFixture():void
{
	super.createFixture();
 
	_fixture.m_reportBeginContact = true;
	_fixture.addEventListener(ContactEvent.BEGIN_CONTACT, handleBeginContact);
}
 
protected function handleBeginContact(e:ContactEvent):void
{
	_contact = e.other.GetBody().GetUserData() as Box2DPhysicsObject;
	if (!e.other.IsSensor())
		explode();
}

I love this way. Anyway, many users ask me to change it… let’s go!

Continue reading Moved from Box2D Alchemy to Box2D AS3

The Citrus Engine meets Away3D

Some days ago, I was thinking that my next post would be the annoucement of the Citrus Engine V3 stable release. Since Starling and Nape are well integrated in the engine and the API very stable, I didn’t see any new big features coming. Oh in fact, I imagined one : 3D support. This one was crazy, and now it is real! Welcome to the first 2D & 3D Flash game engine!

I’m not familiar with 3D. Last year I had a quick look with ThreeJS and then ported it in Away3D. That was my only experience with 3D until now, so don’t hesitate to correct me and to offer some suggestions. That’s lots of new stuff to learn, and that’s pretty exciting!
Also if you have links to free arts/assets Away3D friendly, share please 🙂

For the impatients, here is the demo! Note the Away3D support needs lots of work yet. Click on the red square to add boxes (I was a bit lazy to make a correct button). Use the mouse to move the camera, and right/left/down/space keys for the Hero.
I use Box2D for the physics (it could be Nape), to see the Box2D debug view press tab to open the console and write :

set box2D visible true

All the source code is available on GitHub (with samples) and on GoogleCode (engine code only). The Away3D part will evolve a lot in the next month, the 2D stuff is very stable to use!

Continue reading The Citrus Engine meets Away3D

Tiled Map Editor supported in the Citrus Engine

Some days ago, I received a mail from a guy working on a game with the Citrus Engine. It shows me the progress of his game… another blast!
Let me introduce CynicMusic’s game, one of the greatest platformer game I’ve ever seen made with Starling and the Citrus Engine! He hopes to finish it around Christmas, best wishes for Alex Smith. Play the game, graphics are pixel art, and the music is awesome! I really love the mood. I also want to highlight his work on the gameplay : water, reward box… managed by Box2D Alchemy. Take a look on the FPS, 60fps, yep guys I’m impressed!

I had some discussions with Alex about his workflow, he used the Tiled Map Editor to create his levels then export them as PNG files and finally import in Flash Pro. Using Starling, textures images aren’t bigger than 2048*2048. He has created several CitrusSprite with the different PNGs.

I knew the Tiled Map Editor before, but never gave it a serious look! Quickly it appears that it would be really nice to support it directly, but how can we handle the tmx format provided by the software for our map? I found an article on PixelPracht’s website, he wrote some useful classes to parse the map! He made a quick demo for Flixel game engine. It is also possible to create objects inside the software, great news!

So thanks to his work, all hail to him, I’ve been able to write a parser to handle the Tiled Map Editor’s map in the Citrus Engine! Click here to play the demo.
Graphics are free to use, they come from this website.

This is a screenshot of the level :
tiled map

Since the Citrus Engine is not based on grid for collisions detection, I’ve added platform objects. Mixing grid and physics is quick and really a good thing I think. It offers lots of flexibility : you may use both and keep grid interactivity.

Here is the demo code :
Main class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package tiledmap {
 
	import com.citrusengine.core.CitrusEngine;
 
	[SWF(frameRate="60")]
 
	/**
	* @author Aymeric
	*/
	public class Main extends CitrusEngine {
 
		[Embed(source="/../embed/tiledmap/map.tmx", mimeType="application/octet-stream")]
		private const _Map:Class;
 
		public function Main() {
 
            state = new TiledMapGameState(XML(new _Map()));
		}
	}
}

The TiledMapGameState class :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tiledmap {
 
	import com.citrusengine.core.State;
	import com.citrusengine.math.MathVector;
	import com.citrusengine.objects.platformer.box2d.Hero;
	import com.citrusengine.objects.platformer.box2d.Platform;
	import com.citrusengine.physics.Box2D;
	import com.citrusengine.utils.ObjectMaker;
	import com.citrusengine.view.spriteview.SpriteArt;
 
	import flash.geom.Rectangle;
 
	/**
	 * @author Aymeric
	 */
	public class TiledMapGameState extends State {
 
		[Embed(source="/../embed/tiledmap/Genetica-tiles.png")]
		private const _ImgTiles:Class;
 
		private var _level:XML;
 
		public function TiledMapGameState(level:XML) {
			super();
 
			_level = level;
 
			var objects:Array = [Hero, Platform];
		}
 
		override public function initialize():void {
 
			super.initialize();
 
			var box2D:Box2D = new Box2D("box2D");
			//box2D.visible = true;
			add(box2D);
 
			ObjectMaker.FromTiledMap(_level, _ImgTiles);
 
			var hero:Hero = getObjectByName("hero") as Hero;
 
			view.setupCamera(hero, new MathVector(stage.stageWidth / 2, 240), new Rectangle(0, 0, 1280, 640), new MathVector(.25, .05));
 
			(view.getArt(getObjectByName("foreground")) as SpriteArt).alpha = 0.3;
		}
 
	}
}

Here it works on the classic flash display list. It works also on Starling if level dimensions are not above 2048*2048. I’m thinking to use the tile system made by Nick Pinkham (Citrus Engine contributor member) to handle bigger levels! It has been added to the CE, but it’s not 100% stable at the moment.

Again, all the Citrus Engine works & demo are available on its GitHub. Take a look on the map and the different files. Play with it. Don’t hesitate to test this parser and tell me if some important options are missing.

I’ve also gave a look to the Level Architect’s code (official CE’s level editor, created by Eric Smith), for the first time, and can assure that it needs to much work to keep it supported with the new CE version. I prefer to support format from serious tools (Flash Pro, Tiled Map Editor, Gleed) and continue to work hard on the Citrus Engine.

At the moment I’m working on something very huge for the Citrus Engine and I hope to be able to come back soon with very good news. Stay tuned!