GooglePlay
Спадковість:
Підтримувані платформи:
Available since version:
Опис:
Бібліотека API Гуглплея Таблиця лідерів, Таблиця досягнень, Мультиплеєр
Приклади:
Приклад Мультиплеєру:
Синтаксис: Lua
function print_r (t, indent, done)
done = done or {}
indent = indent or ''
local nextIndent -- Storage for next indentation value
for key, value in pairs (t) do
if type (value) == "table" and not done [value] then
nextIndent = nextIndent or
(indent .. string.rep(' ',string.len(tostring (key))+2))
-- Shortcut conditional allocation
done [value] = true
print (indent .. "[" .. tostring (key) .. "] => Table {");
print (nextIndent .. "{");
print_r (value, nextIndent .. string.rep(' ',2), done)
print (nextIndent .. "}");
else
print (indent .. "[" .. tostring (key) .. "] => " .. tostring (value).."")
end
end
end
require "googleplay"
local isPlaying = false
googleplay:addEventListener(Event.GAME_STARTED, function(e)
--start your game
--go to game scene
isPlaying = true
print("game started")
end)
googleplay:addEventListener(Event.INVITATION_RECEIVED, function(e)
--received an invitation to play, let's play
if not isPlaying then
googleplay:joinRoom(e.invitationId)
googleplay:showWaitingRoom()
--or we can display invitations
--googleplay:showInvitations()
end
end)
googleplay:addEventListener(Event.ROOM_CREATED, function(e)
print("new room created for automatch")
print_r(googleplay:getAllPlayers())
googleplay:showWaitingRoom(2)
end)
googleplay:addEventListener(Event.LOGIN_COMPLETE, function(e)
print("Logged in")
print(googleplay:getCurrentPlayer())
stage:addEventListener(Event.MOUSE_DOWN, function(e)
if not isPlaying then
print("do automatch")
--automatch for min 2 max 2 players
googleplay:autoMatch(2, 2)
--googleplay:showWaitingRoom(2)
--googleplay:invitePlayers(2, 2)
--googleplay:showInvitations()
end
end)
end)
googleplay:addEventListener(Event.LOGIN_ERROR, function(e)
print("LOGIN_ERROR")
end)
googleplay:login()
done = done or {}
indent = indent or ''
local nextIndent -- Storage for next indentation value
for key, value in pairs (t) do
if type (value) == "table" and not done [value] then
nextIndent = nextIndent or
(indent .. string.rep(' ',string.len(tostring (key))+2))
-- Shortcut conditional allocation
done [value] = true
print (indent .. "[" .. tostring (key) .. "] => Table {");
print (nextIndent .. "{");
print_r (value, nextIndent .. string.rep(' ',2), done)
print (nextIndent .. "}");
else
print (indent .. "[" .. tostring (key) .. "] => " .. tostring (value).."")
end
end
end
require "googleplay"
local isPlaying = false
googleplay:addEventListener(Event.GAME_STARTED, function(e)
--start your game
--go to game scene
isPlaying = true
print("game started")
end)
googleplay:addEventListener(Event.INVITATION_RECEIVED, function(e)
--received an invitation to play, let's play
if not isPlaying then
googleplay:joinRoom(e.invitationId)
googleplay:showWaitingRoom()
--or we can display invitations
--googleplay:showInvitations()
end
end)
googleplay:addEventListener(Event.ROOM_CREATED, function(e)
print("new room created for automatch")
print_r(googleplay:getAllPlayers())
googleplay:showWaitingRoom(2)
end)
googleplay:addEventListener(Event.LOGIN_COMPLETE, function(e)
print("Logged in")
print(googleplay:getCurrentPlayer())
stage:addEventListener(Event.MOUSE_DOWN, function(e)
if not isPlaying then
print("do automatch")
--automatch for min 2 max 2 players
googleplay:autoMatch(2, 2)
--googleplay:showWaitingRoom(2)
--googleplay:invitePlayers(2, 2)
--googleplay:showInvitations()
end
end)
end)
googleplay:addEventListener(Event.LOGIN_ERROR, function(e)
print("LOGIN_ERROR")
end)
googleplay:login()
Методи, евенти та властивості:
Методи
Методи та властивості, які підтримуються як Android, так і iOS, відмічені зелений- googleplay:login() --login
- googleplay:logout() --logout
- googleplay:showSettings() --show settings screen
- googleplay:showLeaderboard(leaderboardId) --show leaderboard screen
- googleplay:reportScore(leaderboardId, score [,immediate]) --post score to service
- googleplay:showAchievements() --show achievements screen
- googleplay:reportAchievement(achId [, numSteps, immediate]) --achievement unlocked or progressed by specified amount of steps of total defined steps
- googleplay:loadAchievements() --retrieve all defined achievemenets
- googleplay:loadScores(leaderboardId [,timespan, participants, maxResults]) --retrieve all scores for specific leaderboard ina specific timespan for specific participans
- googleplay:loadPlayerCenteredScores(leaderboardId [,timespan, participants, maxResults]) --retrieve all scores for specific leaderboard ina specific timespan for specific participans
- googleplay:autoMatch(minPlayers, maxPlayers) --create a quick game between randomly selected players
- googleplay:invitePlayers(minPlayers, maxPlayers) --allow user to invite players to a game
- googleplay:joinRoom(invitationId) --joins the game you've been invited to
- googleplay:showInvitations() --show screen for managing invitations
- googleplay:showWaitingRoom(minPlayers) --show waiting room before the game with the list of players
- googleplay:sendTo(playerId, data, isReliable) --send data to specific user by id
- googleplay:sendToAll(data, isReliable) -- send to all users
- googleplay:getPlayerName() --get your current user name
- googleplay:getPlayerId() --get your current user id
- googleplay:getPlayerScore() --dispatches PLAYER_SCORE_COMPLETE event
- googleplay:getAllPlayers() --retrieve information (id and name) for all users involved in game
- googleplay:loadState(key) --load app state from slot key from the cloud
- googleplay:updateState(key, data[, immediate]) --update app state for slot key with data bool immediate if it needs to be saved immediately
- googleplay:deleteState(key) --delete app state for slot key
- googleplay:resolveState(key, version, data) --resolve state conflict for slot key with version and data
Властивості
- GooglePlay.UNLOCKED --achievement state unlocked
- GooglePlay.REVEALED --achievement state available to user
- GooglePlay.HIDDEN --achievement state unknown to user
- GooglePlay.ALL_TIME --leaderboard timespan all time
- GooglePlay.WEEK --leaderboard timespan week
- GooglePlay.TODAY --leaderboard timespan today
- GooglePlay.FRIENDS --leaderboard participants
- GooglePlay.ALL_PLAYERS --leaderboard participants
Подї
Ігрові Події
- Event.DATA_RECEIVED
- event.sender
- event.data
- Event.GAME_STARTED
- Event.REPORT_ACHIEVEMENT_COMPLETE
- event.achievementId
- Event.LOAD_ACHIEVEMENTS_COMPLETE
- event.achievements
- event.achievements[].id
- event.achievements[].name
- event.achievements[].description
- event.achievements[].status
- event.achievements[].currentSteps
- event.achievements[].totalSteps
- event.achievements[].lastUpdate
- Event.REPORT_SCORE_COMPLETE
- Event.LOAD_SCORES_COMPLETE
- event.name
- event.leaderboardId
- event.scores
- event.scores[].name
- event.scores[].timestamp
- event.scores[].formattedScore
- event.scores[].score
- event.scores[].rank
- event.scores[].playerId
- Event.PLAYER_SCORE_COMPLETE
- event.rank
- event.formattedScore
- event.score
- event.timestamp
Події Авторизації
- Event.LOGIN_ERROR
- Event.LOGIN_COMPLETE
Подї Хмари
- Event.STATE_LOADED
- event.key
- event.isFresh
- event.data
- Event.STATE_ERROR
- event.key
- Event.STATE_CONFLICT
- event.key
- event.version
- event.localData
- event.serverData
- Event.STATE_DELETED
- event.key
Події Кімнати
- Event.DISCONNECTED_FROM_ROOM
- event.roomId
- Event.ROOM_CREATED
- event.roomId
- Event.LEFT_ROOM
- event.roomId
- Event.ROOM_CONNECTED
- event.roomId
- Event.CONNECTED_TO_ROOM
- event.roomId
- Event.ROOM_CONNECTING
- event.roomId
- Event.ROOM_AUTO_MATCHING
- event.roomId
- Event.JOINED_ROOM
- event.roomId
- Event.INVITATION_RECEIVED
- event.invitationId (can be used to connect to room)
Peer Подї
- Event.PEER_INVITED
- Event.PEER_JOINED
- Event.PEER_DISCONNECTED
- Event.PEER_CONNECTED
- Event.PEER_LEFT
- Event.PEER_DECLINED
Немає коментарів:
Дописати коментар