Mittwoch, 26. Dezember 2012

Corona SDK and Lua: Creating a rotating obstacle with a physics joint

Android app on Google Play



As you might have seen in our game Cookie Billiard, we created some rotating elements that are used as obstacles for the cue or as levers for the cookie. This kind of element can be created by using the standard physics joints that corona sdk offers (http://developer.coronalabs.com/content/game-edition-physics-joints). However, there is no physics joint that is specifically indended for such a purpose. We realised it by using the standard pivot joint that is also used to create ragdoll figures.


physics.newJoint( "pivot", object1, object2, 200,300 )


The pivot joint in general connects two display objects by creating an imaginary line that starts at the center of the first object and ends at the center of the second object (resp. vise versa). The coordinates (here 200,300) specifiy a point where the lines, and the objects that are connected to it, can rotate around.


The movements of the two objects are now controlled by the joint and its break point. They can't rotate around the origin of its connecting line. But now a precularity of corona sdk comes into play: when the two obects lie on top of each other, the last restriction does not hold anymore and they can rotate around the origin of its connecting line.

 So we just created the circle first and made it static so that it can't move:


myCircle = display.newCircle(100, 100, 10 )    
physics.addBody (myCircle, "static", {radius = 10, bounce = 0.5,  friction = 0.65})

Then we created a rectangle that lies on top of the rectangle as illustrated in the picture. Important is that you do not set its physics body to "static" sinse it should be able to move:
       physics.addBody (myRotator, {density = 4, bounce = 0.5,  friction = 0.65})

Eventually, we added a pivot joint that connected the circle and the rectangle:
       physics.newJoint ("pivot", myCircle, myRotator, myCircle.x, myCircle.y)

An important  property here is the desity (in this case set to 4) of the physics body of the rectangle. If it set to low and the cue later on hits the rectangle, it might happen that the rectangle and the circle move slightly away from its origin which looks strange and leads to strange rebounds of the cue. It seems to be a bug of corona sdk that has not been solved yet. I found some other users in different forums also complaining about this problem. 

I hope this post was helpful for you.

Your MOCCA GAMES team.

Android app on Google Play

Corona SDK: removing standard permissions from AndroidManifest.xml

Android app on Google Play Hey,

now i want to dig into a topic that was really annoying to us in the development of Cookie Billiard. For some reason Corona SDK ALWAYS includes the following permissions in the androidManifest.xml:


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

There is no easy way to remove them from within corona. The settings file is not able to remove those permissions. Corona itself, does not provide an official solution to that. So here I'm explaining it to you:

1) Download the APK manager. I used version 5.0.2
In order for the APK-Manager to work properly you need to have your JDK (Java Development Kit) "bin" folder added to your PATH environment variable

2) Put the .apk that needs to be changed in the folder "place-apk-here-for-modding"
3) run the script and choose option 9 for decompiling

4) Go into the projects folder of the APK Manager and change the androidManifest.xml to your likings
5) Run option 11 (compile) in the APK Manager script, then you will be confronted with two questions: answer them both with "2". Then the following question pops up:
Now go into the "keep" folder and just delete androidManifest.xml and resources.arsc and then hit enter in the script (or any other key)

6) Now you have successfully compiled your .apk without the permissions in the androidManifest.xml. However thats not enough for the android market. Now you still need the sign the .apk with your certificate and you need to run zipalign in order to align your package structure according to the google standards.

7) Signing the app with jarsigner.
Jarsigner is a standard cmd-application that comes witht the JDK. If you don't have that download it and add the bin folder of the JDK to your Path environment variable.

Then perform the following command in your console according to your own folders:

jarsigner -verbose -keystore C:\...\releaseKey.keystore C:\...\Apk_Manager_5.0.2\place-apk-here-for-modding\unsignedCookieBilliard.apk moccagames

You will then be asked for the password of your keystore-file. enter it and all your files should successfully be signed.

8) Now you need to zipalign you signed .apk:

zipalign is a cmd-tool that comes with the Android Development Kit. You already needed it in order to run the APK-manager. However for the APK-Manager you just needed to add the "platform-tools" folder to your PATH environment variable. The zipalign tool resides within the "tools" folder of the Android SDK. If not already done add it to your PATH-variable.

Perform the following command in your console according to your own folders
zipalign -f -v 4 C:\...\CookieBilliard.apk C:\...\CookieBilliardZipAlign.apk

If everything was successfull a "Verifiaction successfull" message should appear at the end.
Now you have the same .apk like in the beginning, just without the permissions that you removed, ready to be uploaded to the android market :)

Hope the tutorial is helpful. If there are any questions please post them in the comments.

Your MOCCA GAMES team

!!!IMPORTANT: Do never try to change .apks that are not yours!!! We are not responsible for any legal issues that may arise from that!!! Android app on Google Play

Montag, 24. Dezember 2012

Corona SDK lua tutorial: Callback functions

Hey guys,

during development we've realized that so called callback function are a very usefull system to create reusable code that makes life easier. We've used that system in our slide-View that we've implemented as our game selection menu in Cookie Billiard  Android app on Google Play .



The idea and purpose of callback functions:

A callback function atually is nearly the same as an EventListener. You specifiy which method should be called in case a certain event occures. In the context of the slide view a certain method should be called if a user clicks on a specific slide. In order to make it reusable the method is not allowed to be located within the slide view module, but outside of it. You pass a certain function into the slide view module.

Have a look at the new function of our slidev view module:

function slideView:new( svTop, svLeft, images, keys, callback )
...
end

Here we pass the distance to the top, to the left, all images, their keys and a function that should be called whenever a slide was clicked (tapped in corona terms).

To use the passed callback function you can use the following listener:


function onImageTap( touchEvent )
        callback( { key = touchEvent.target.tag } )
        return true
end



Our callback function than looks like this:

This function is not part of the slide view module but resides outside!


local function onSelectSlideViewItem( slideViewItem )
        print( "Clicked " .. slideViewItem.key )

        if (slideViewItem.key == "minigames") then
            director:changeScene( "scripts.levels.training.levelSelectionTraining", "moveFromTop" )
        elseif (slideViewItem.key == "gameCrispy") then
            director:changeScene( "scripts.levels.crispy.levelSelectionCrispy", "moveFromTop" )
        elseif (slideViewItem.key == "introduction") then
            director:changeScene( "scripts.levels.introduction.introduction", "moveFromTop" )
        elseif (slideViewItem.key == "gameCrunchy") then
            director:changeScene( "scripts.levels.crunchy.levelSelectionCrunchy", "moveFromTop" )
        end
end

The callback function receives a certain item that was clicked and can decide upon that what action has to follow.

Our System of a slideview makes it perfectly reusable. W can use it for any other game. We just have to pass all the required parameters and thats it for the slideview.

Your MOCCA GAMES team
Android app on Google Play

Cookie Billiard: removed unsave permissions

Hey folks,

due to some feedback we received, we removed all unnecessary permissions. The free version now just needs INTERNET ACCESS and the full version doesn't need any permissions :).

Have fun playing our game:
New Android Release

Your MOCCA GAME team

Sonntag, 23. Dezember 2012

Freitag, 21. Dezember 2012