With the game now uploaded to a server it is available for anyone in the world to play it. They can play the game, that is, if they know about it. One of the most difficult challenges any developer faces is getting the word out about their product. One of the easiest ways to spread the news is through social media sites, such as Facebook. GameMaker: Studio makes this easy as the functionality for connecting with Facebook is already integrated. We are going to add a Facebook login button to the frontend of the game, and we will add the ability for the player to post their scores to their Facebook walls.
To learn more about Facebook Open Graph, App Namespaces, and more, check out the Facebook Developers API Documentation at https://developers.facebook.com/docs/reference/apis/.
http://
or any other element beyond the name of the root site.scr_Global_Facebook
, with the following code:facebook_init(); globalvar permissions; permissions = ds_list_create(); ds_list_add(permissions, "publish_stream");
We start by initializing Facebook, and then we create a global variable for a ds_list
that will contain all the permissions we want to be able to request from Facebook. In our case we are just asking to be able to publish to the Facebook wall of the logged in user. All the options that are available can be found on the Facebook Developers' site.
scr_Global_GameStart
and execute the following line at the end:scr_Global_Facebook();
Now that we have Facebook active, we can implement it into the game. We will start by adding a login button.
spr_Button_FacebookLogin
, with Remove Background unchecked, load Chapter 9/Resources/Sprites/FacebookLogin.gif
, and center the origin.obj_Button_FacebookLogin
, attach the sprite we just created, and then set Parent to obj_Button_Parent
.scr_Button_FbLogin_MousePressed
, and have the user log in to Facebook.facebook_login(permissions);
MainMenu
and add a single instance of the button below the START button.spr_Button_FacebookPost
, with Remove Background unchecked, load Chapter 9/Resources/Sprites/FacebookPost.gif
, and center the origin.scr_ScoreScreen_Create
, and add a variable for the Y placement, width offset, and height offset of the button.postfb_Y = 340; postfb_OffsetW = 64; postfb_OffsetH = 16;
scr_Menu_Button_FbPost
, which will control the functionality.if (isVictory) { status = facebook_status() if (status == "AUTHORISED") { draw_sprite(spr_Button_FacebookPost, 0, screenX, postfb_Y); if ((win_Y > postfb_Y - postfb_OffsetH && win_Y < postfb_Y + postfb_OffsetH)) { if ((win_X > screenX - postfb_OffsetW && win_X < screenX + postfb_OffsetW)) { { draw_sprite(spr_Button_FacebookPost, 1, screenX, postfb_Y); if (mouse_check_button_pressed(mb_left)) { myTitle = "Destruct"; myCaption = "Play this game at yournamesite.com" myText = "I just destroyed the " + room_get_name(room) + " Towers playing Destruct!"; myImage = "http://yoursitename.com/Destruct/Thumbnail.gif"; mySite = "http://yoursitename.com/Destruct/" facebook_post_message(myTitle, myCaption, myText, myImage , mySite, "", ""); } } } } } }
We only want to post to Facebook if the player defeats a level, so we start by checking the win condition. We check the status of the Facebook connection, as we want to display the button only if the player is signed in. If the player is signed in, we draw the button on the screen and check to see if the mouse is hovering over it, as we did with all our other buttons. If the button is clicked, we create some variables for the message title, caption and text, an image, and a link back to the site. We then post a message to Facebook. The function also has two additional parameters that are for using more advanced Facebook actions, but we are leaving these blank.
To see what advanced options are available, see the Facebook Developers' API Post page at https://developers.facebook.com/docs/reference/api/post/.
scr_ScoreScreen_DrawGUI
and execute the script we just created:scr_Menu_Button_FbPost();
Chapter_09/Resources/Extras/
and transfer Thumbnail.gif
over to the server into the Destruct
folder.Congratulations! The game is now available for everyone to play and is being exposed to the world through Facebook. The goal for any developer is to create interesting games that everybody enjoys playing and is able to complete. But how do you know whether that is occurring? Are people getting stuck in the game? Is it too easy? Too hard? After all the hard work that went into making the game, it would be a shame to not know any of these answers. This is where analytics come in handy.
18.188.227.4