Monday 2 June 2014

How save highscores in local database in Construct 2 game

You have made a game on construct 2 and you want to save the high scores of the player in the local database. Here is a way you can save the high scores of the player in the local database. First of all you will have to add two object into your layout, one for the scores and other for the high scores. The following image is showing the objects of scores and high scores on the layout. 


Now on the event sheet, you need to add two global variables score=0 and highscore=0. Now on the layout you need to add local database object as shown in the image below


Now on the event (Start of layout), you need to make a sub event where select an object webstorage, local key and write HighScore(same as the global variable as it is case sensitive) in the double quotes and click done. In that event set high score to the local web storage. Click on system action, set value, variable should be "HighScore"(same as the global variable as it is case sensitive) and value should be WebStorage.LocalValue("HighScore"), click done. After that set text of the hightscore object to the highscore(this is global variable). Check make another else event and set highscore to 0 and set text of the hightscore object to the highscore(this is global variable). All the steps are shown in the below image.


Now to change the high score when the player dies, what you need to do is to check whether the new scores are greater than the previously high scores that are already stored in the database. When the player collide the with the enemy or player is dead you need to add another sub event which checks whether the new scores are greater than the previous high scores or not. If new new high scores are greater, update the local database with the new score as shown in the image below (which is the example of one of my game).



Now when you play the game at start, the high score will be zero, after that if new scores are greater than the previous scores, new scores will be stored in the local database. You are done :)

Saturday 31 May 2014

How to add pubcenter ads in Construct 2 game

If you have made a window 8 game on construct 2 and you want to earn from your game. Here is a way you can add pub center ads in your game. First of all you must have a window 8 or 8.1 in your system and a copy of visual studio 2012 or later that should be installed in your system. In your visual studio you must have Microsoft advertising SDK installed. Now to add ads in construct 2 game you will have to download a window 8 plugin from HERE. Drag that downloaded file into the construct 2 window. It will show that following window

Install the required plugin, and restart construct 2. After that open the create new object window as shown in the image below

You will see a "Window 8 advertising" object will be appear in this window. Insert a new object of it and you can see that the default size is 250 x 250 but you can change it following the available ads sizes in pub center. Details related to it are given in the following LINK. You can change different properties of this ad as shown in the below image

After doing all these settings, export your game to visual studio (see, how to export from HERE). Right Click the solution and Add reference and check the Microsoft advertising SDK and click OK.


After that you will need the add the following line of code just below the base.js and ui.js file in index.html file
<script src="///MSAdvertisingJS/ads/ad.js"></script>

At the end, enable the internet capabilities in the package.appxmanifest file. You are done :)