Showing posts with label iphone. Show all posts
Showing posts with label iphone. Show all posts

Sunday, January 30, 2011

Difference between Android's and iPhone's Accelerometer

Today I was playing with Android's accelerometer. I am in the process of closing cocos2d-x's issue 242.

Basically I finish coding my first approach but when I run it with the test case the ball went exactly to the opposite side.
I started checking if I was sending the parameters correctly and unfortunately I was doing the right thing :(.

Since the test case was done for an iphone device I checked if the iphone used the same coordinates as Android.

I found two useful links to read about both's accelerometer:
* iphone-tutorial-reading-the-accelerometer
* SensorEvent's doc

If you check the following screens you will notice what I am talking about:





Not completely sure of what was going on I downloaded a demo app to check it gave the same values as my code. We both were sending the same coordinates so there was something different between iphone's and Android's accelerometers.

I ended up download an iphone demo app to check what were the values read. You can see the different outputs with both devices placed in the same position:




Notice the difference in the z axis value.
To fix it, it was just a matter of multiplying by -1 every value from Android's accelerometer.

Sunday, January 16, 2011

Cocos2d's Android flavors

You don't know cocos2d?

Cocos2d started as a python game framework to be used on a competition called PyWeek. The name comes from a city in Córdoba, Argentina called "Los cocos". Cocos2d was born there in a PyCamp by PyAR during 2008.

You will notice that all coocos' tests have a character named Grossini. AFAIK it comes from the PyWeek game: Grossini's Hell.

Afterwards, Ricardo Quesada, one of the creators of cocos2d, ported cocos2d to objective-c and cocos2d-iphone was born. Cocos2d-iphone is far more known that the python version and it's used in a whole bunch of top10 games in the AppStore.

Hey, what does this have to do with Android?
Well, it's just an introduction :).
For android we have two flavors.

* Cocos2d-android (Java version)
* cocos2d-x (c++ version)

I have been testing both trying to decide which one to use to build a game so I will provide some sort of pros/cons of each one.
Both versions are coded by Chinese people so it was difficult to get in touch because of the different timezones.

Android version:

Pros:
* Coded in Java.
* Excellent support. I sent an email to ZhouWeikuan with an issue and he fixed it right away.

Cons:
* Tested on my gf's ldpi device and the scrolling feels slower. I guess there is an issue with density.
* Didn't feel stable.

C++ version:

Pros:
* Multiplatform.
* Organized development with a Roadmap

Cons:
* C++ (Perhaps it's not a cons for you but my C++ skills are a bit rusty)
* Tested on my gf's ldpi device and although it said 50fps it "flickered" a lot. EDIT: This generated an issue in cocos2d-x issue tracker.
* Didn't feel stable.


My conclusions:

Both versions felt unstable. I feel that if I need to do a game I will need to look into the framework src code and fix stuff to make it work correctly but If you are doing a game...

...which does not require a good amount of FPS => java version.
...from the scratch and you will port to different platforms => c++ version.

Also, I would totally recommend to clone both versions repos and play a little with them.
It has been a fun experience for me!

Enjoy!