I’m creating a very simple point and click game using Composer and having multiple scenes.
I’d like to have the player click on the rectangle (a door) and gain a points. the rectangle is also the trigger that sends the player to the next scene (room). If the player clicks on anything but the rectangle he looses points and remains in the scene (room). I’d like to only reveal the score on the final scene (room).
I’m able to transition from room to room but I can’t figure out how to add a score and have it carry over to the final slide for display.
I’ve been reading a lot on the subject but the information is not always clear on where I say what?
Thanks in advance.
Here is an example of my code:
local composer = require( “composer” )
local scene = composer.newScene()
local score = 0
composer.setVariable( “addToScore”, 100 )
– Code outside of the scene event functions below will only be executed ONCE unless
– the scene is removed entirely (not recycled) via “composer.removeScene()”
– Initialize variables
local options = {
effect = “fade”,
time = 50000,
params = {
someKey = “someValue”,
someOtherKey = 10
}
}
local function gotoScene2()
composer.gotoScene( “scene2”, “addToScore” )
end
–local function addToScore(num)
--score = score + 10
–end
local function addToScore(num)
score = score + 200
scoreText.text = "Score: " … score
print(score)
end
– Scene event functions
– create()
function scene:create( event )
local sceneGroup = self.view
– Code here runs when the scene is first created but has not yet appeared on screen
local image1 = display.newImageRect(“Slide001.png”, display.contentWidth, display.contentHeight)
image1.anchorX = 0
image1.anchorY = 0
image1: toBack( )
local rectangle1 = display.newRect( 110, 290, 100, 100 )
rectangle1.alpha = .1
rectangle1:addEventListener ( “tap”, gotoScene2, onTapped )
end