Go back

If your game’s players have beaten or are starting to get bored of your game, building a shop for unlockable items or characters is a great way to build replay value and retention. In this tutorial, we are going to cover how to build an in app shop where your users “Buy” items with the points they generated in your game!

In this example, our game will be very simple: just keep clicking to get more points! If you want to get more points per click, upgrade your “Player”. Feel free to make your game as simple or complex as you want. To start, we are going to setup our currency system that will be shared across all scenes.

IMG_9390.jpeg

Displaying Currency

The first thing we’re going to do is to go on the Global UI and add a Label that will represent our currency and set the text to be 0. Also, add another label to tell us what that label is. The player will be able to see how much money they have. Feel free to stylize the labels to your liking!

IMG_9344.png

 

Persisting Currency

We want to make sure that the amount of money we have saves between sessions. This means having the money amount save during gameplay, and also having the amount be loaded when the player is returning to the game. We can select the label representing our currency amount and edit its behaviors to make this work.

IMG_9343.png

Let's start by working on saving the currency amount to file. We want to be able to trigger saving from anywhere in the scene, so let's add a Receive Message behavior. In our case, let's have it listen to the saveMoney event. 

IMG_9350.jpeg

This behavior can be triggered by any Broadcast Message behavior in the scene broadcasting with the saveMoney event. This means we'll be able to trigger saving whenever and wherever we want. 

Now, we want to get the currency amount to save, so let's add Get Label and connect Receive Message to it. Make sure you're getting the value of the currency amount label.

IMG_9351.jpeg

Now that we have the currency amount we want to save, let's add a Modify Save File behavior and connect Get Label to it. In the behavior, make sure the modification is set to Set Key and the key type is set to Existing. 

IMG_9352.jpeg

Tap on Select or Create Key to create a key and enter Money in the text field. Press the + button to create the key. Your behavior should now be referring to the Money key. This key will be tied to the currency amount that will be stored to the save file, so when we want to retrieve it later, we can refer to the same key again. You can name your key anything you want, just make sure you use the same key to retrieve the same saved data. Your behavior should look like what is shown below.

IMG_9348.jpeg

Now, we want to get the text output from the Get Label behavior and plug it into the Modify Save File behavior.

IMG_9355.gif

Congratulations, the saving functionality complete! What the behaviors above are doing is getting the label (representing the currency amount) and then saving it to file every time the saveMoney event is broadcasted from a Broadcast Message behavior.

We'll get to how to trigger saving later, but for now, let's work on loading the currency amount from file. Add a Frame Event behavior and set it to trigger on Scene Start. This is what will trigger the loading before the scene runs. Make sure Trigger on Restart is enabled so this can trigger when the scene also restarts.

IMG_9345.jpeg

Add a Load from File behavior, then connect the Frame Event behavior to it. From here, you can select the preexisting Money key that we've created earlier.

IMG_9356.jpeg

The Default Value is the amount of currency the player should start with. In our case, we'll enter 1000. The default value is what will be loaded if the player does not have a previously saved value associated with a key.

IMG_9357.jpeg

At this point, we have successfully loaded the value but we're not doing anything with it. In this case, we want to update the currency amount label to display the loaded value. Let's add a Set Label behavior to do just that!

IMG_9358.jpeg

Plug the loaded value from Load from File to Set Label like so.

IMG_9360.gif

Congratulations, you can now save and load currency! Your behaviors should look something like shown below - on the left is the saving functionality and on the right is the loading functionality.

IMG_9361.png

Earning Currency

We haven't actually added a way to earn currency yet. You can have your player earn it through various means, but in our case, we'll keep it simple and have the player make money by tapping a cookie. Sound familiar? 

We have a cookie graphic in the scene and we want to make it so when we tap on it, we earn one point. Let's edit its behaviors.

IMG_9364.png

Now let's have it so when the player touches the cookie, it'll add the money amount by 1. Make sure the correct label is selected!

IMG_9365.jpeg

This works but it doesn't save yet. After adding or subtracting currency, we should save changes by using the Broadcast Message behavior like so - this behavior should be used every time to trigger a save to occur. We're reusing the saveMoney event key that we have used in the Receive Message behavior when we were creating the save functionality.

IMG_9366.jpeg

Awesome, now you've got a working persistent currency system! At this point, you can tap the cookie as much as you want and it'll save your progress. When you leave and come back, your currency amount should be where it previously was.

Setting Up the Shop

Now that you've got a proper currency system going on, let's add a way for your player to spend their money and get something in return! Create a new layer called Shop. This is where we can design our shop the way we want. Feel free to design it however you like.

We're going to have only two items in the shop for the sake of time and ease, but you can add as many as you want. In this case, our items are:

  • Click Multiplier - How many points you earn when clicking the cookie. It'll cost 100 currency to increase this by 1.
  • Passive Income - How many points you earn every second. It'll cost 200 currency to increase this by 20.

IMG_9367.png

Make sure there's a way for the player to actually enter and exit the shop. In this case, we're simply hiding and showing the Shop layer. There are no other behaviors other than these.

IMG_9368.jpeg
IMG_9369.jpeg

 

Just like what we did with the currency amount label, let's make the Click Multiplier and Passive Income load and save the same way. We'll use the exact same behaviors like before.

IMG_9377.jpeg
IMG_9374.jpeg
IMG_9378.jpeg
IMG_9376.jpeg

Now, let's work on the Click Multiplier item. We will go to the BUY label under it and edit its behaviors.

IMG_9370.png

Have it so when the player touches the BUY label, we first get the amount of currency the player has. We can use Get Label and have it select the currency amount label.

IMG_9372.jpeg
IMG_9371.jpeg

You can have an If behavior check if the player doesn't have enough money to buy this item. You can alert the player if so. In this case, if the player has less than 100 points, then the Alert behavior will notify the player.

IMG_9373.jpeg

In the other hand, if the player does have enough currency to buy this item, then we can simply add Click Multiplier by 1.

IMG_9380.png

Don't forget to also subtract the currency by the cost and save it! You wouldn't want your players to get this item for free, right?

IMG_9384.png

Let's do the same thing for Passive Income. The only that changes is the cost, which label to add to and what to save.

IMG_9385.png

Great job, now you have a functioning shop! But these items currently don't have any effect in gameplay and are solely just numbers - let's work on that next.

Giving the Shop Items Use

We have already established what we want our shop items to do:

  • Click Multiplier - How many points you earn when clicking the cookie. It'll cost 100 currency to increase this by 1.
  • Passive Income - How many points you earn every second. It'll cost 200 currency to increase this by 20.

Let's make these items do what they should actually do - starting with Click Multiplier. In the behaviors of the cookie, we can have the multiplier value loaded from file like so.

IMG_9382.jpeg

Then we can use the loaded value as the amount to add to the currency.

IMG_9383.jpeg

Every time we tap on the cookie, the multiplier is retrieved from file then it is added to the currency. With that done, we can now work on the Passive Income. Let's add a label and name it accordingly - this will be where the behaviors for this will be. This label shouldn't be visible to the player, so hide it outside of the screen.

IMG_9386.png

In the behaviors, we can set up a 1 second Timer which repeatedly gets the Passive Income amount.

IMG_9387.jpeg

Now, we want to have the currency increase by the passive income amount and have it save each time like so.

IMG_9388.jpeg

Where do I go from here?

Well done! You now have a working shop and currency system! Although it doesn't look very pretty, you can stylize it to your like and expand on it.

IMG_9389.png

You are able to buy useful items in the shop with your money. Feel free to add more shop items, more ways to earn currency or even polish it! Currently, the prices of the items don't change when buying them. This makes it super easy to buy them as you earn more. Do you think you can make the prices increase as you buy them?

Feel free to add different shops and use the currency system in other scenes!

If you would like to download the project for yourself, download it here!

Be in the know

Be the first to hear about new blogs, updates and fun events!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

recent posts

See all posts