error in game development

hello 

i was facing the error in this line 54

– Change the center point to bottom left

screenText:setReferencePoint(display.BottomLeftReferencePoint);

– Place the text on screen

screenText.x = _W / 2 - 210;

screenText.y = _H - 20;

and its saying cannot implement in 1.0 something like that instead of that use anchorpoint

any solutions please i have also updated main file in the form off text 

setReferencePoint has been outdated 

Use anchor points instead

screenText.anchorX = 0 

screenText.anchorY = 0 

this will place your reference point to top left

if you want bottom left, then :

screenText.anchorX = 0

screenText.anchorY = 1 

https://coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/

Can u please help me out ??? Where all I need to do replace ??? With reference to the attached file…

Instead of: (in other words remove this line)

screenText:setReferencePoint(display.BottomLeftReferencePoint);

and in its place write:

screenText.anchorX = 0  -- 0 is left, 0.5 is center, 1 is right screenText.anchorY = 1 -- 0 is top, 0.5 is center, 1 is bottom

But you need to understand what this is about.  In Corona all display objects are basically rectangles. While circles and lines are not rectangles, they still have a bounding box making them a virtual rectangle.

By default Corona SDK with Graphics 2.0 (today’s standard) every display object if you don’t make changes, has their .x and .y mean the center of the object. That is you position everything by its center. In really old version of Corona SDK, what we call Graphics 1. Some objects were positioned assuming .x and .y were the top left corner of the rectangle. Others were centered. There was no consistency.

In both cases, Graphics 1 and today’s Graphics 2, we allowed you to change the rules on where an object was drawn. Graphics one used :setReferencePoint() and you could provide 9 basic locations like display.TopCenterReferencePoint or in your example display.BottomLeftReferencePoint. If you set .x and .y to 100 and 100, the bottom left point of the box would be at 100, 100.

Graphics 2.0 got rid of ReferencePoints and introduced .anchorPoints (.anchorX and .anchorY). By setting these to a value between 0 and 1 you could put the .x and .y value to be any where within the bounding box and a later update allows for negative numbers and numbers greater than one that lets you put the .x and .y outside the box.

Why would you want to do this?  If you’re creating a bunch of display.newTextObjects and you want them all to left-align you can change the .anchorX to 0 and now they will all align nicely. Want to position something at the bottom of the screen?

object.y = display.actualContentHeight

object.anchorY = 1

Rob

still the error is their in 146 line 

as setanchopoint(nil)

– Hide status bar

display.setStatusBar(display.HiddenStatusBar);

– Display a background image

–[[ Here we are inserting

a background image of clouds --]]

local background = display.newImage(“images/clouds.png”);

– Generate Physics Engine

local physics = require(“physics”);

– 1. Enable drawing mode for testing, you can use “normal”, “debug” or “hybrid”

physics.setDrawMode(“normal”)

– 2. Enable multitouch so more than 1 balloon can be touched at a time

system.activate(“multitouch”);

– 3. Find device display height and width

_H = display.contentHeight;

_W = display.contentWidth;

– 4. Number of balloons variable

balloons = 0;

– 5. How many balloons do we start with?

numBalloons = 100;

– 6. Game time in seconds that we’ll count down

startTime = 20;

– 7. Total amount of time

totalTime = 20;

– 8. Is there any time left?

timeLeft = true;

– 9. Ready to play?

playerReady = false;

– 10. Generate math equation for randomization

Random = math.random;

– 11. Load background music

local music = audio.loadStream(“sounds/music.mp3”);

– 12. Load balloon pop sound effect

local balloonPop = audio.loadSound(“sounds/balloonPop.mp3”);

– Create a new text field using native device font

local screenText = display.newText("…Loading Balloons…", 0, 0, native.systemFont, 16*2);

screenText.xScale = 0.5

screenText.yScale = 0.5;

– Change the center point to bottom left

screenText.anchorX = 0

screenText.anchorY = 0

– Place the text on screen

screenText.x = _W / 2 - 210;

screenText.y = _H - 20;

– Create a new text field to display the timer

local timeText = display.newText("Time: "…startTime, 0, 0, native.systemFont, 16*2);

screenText.anchorX = 0.5

screenText.anchorY = 0.5;

timeText.x = _W / 2;

timeText.y = _H - 20;

local gameTimer;

– Did the player win or lose the game?

local function gameOver(condition)

– If the player pops all of the balloons they win

if (condition == “winner”) then

screenText.text = “Amazing!”;

– If the player pops 70 or more balloons they did okay

elseif (condition == “notbad”) then

screenText.text = “Not too shabby.”

– If the player pops less than 70 balloons they didn’t do so well

elseif (condition == “loser”) then

screenText.text = “You can do better.”;

end

end

– Remove balloons when touched and free up the memory they once used

local function removeBalloons(obj)

obj:removeSelf();

– Subtract a balloon for each pop

balloons = balloons - 1;

– If time isn’t up then play the game

if (timeLeft ~= false) then

– If all balloons were popped

if (balloons == 0) then

timer.cancel(gameTimer);

gameOver(“winner”)

elseif (balloons <= 30) then

gameOver(“notbad”);

elseif (balloons >=31) then

gameOver(“loser”);

end

end

end

local function countDown(e)

– When the game loads, the player is ready to play

if (startTime == totalTime) then

– Loop background music

audio.play(music, {loops =- 1});

playerReady = true;

screenText.text = “Hurry!”

end

– Subtract a second from start time

startTime = startTime - 1;

timeText.text = "Time: "…startTime;

– If remaining time is 0, then timeLeft is false

if (startTime == 0) then

timeLeft = false;

end

end

– 1. Start the physics engine

physics.start()

– 2. Set gravity to be inverted

physics.setGravity(0, -0.4)

–[[ Create “walls” on the left, right and ceiling to keep balloon on screen

display.newRect(x coordinate, y coordinate, x thickness, y thickness)

So the walls will be 1 pixel thick and as tall as the stage

The ceiling will be 1 pixel thick and as wide as the stage

–]]

local leftWall = display.newRect (0, 0, 1, display.contentHeight);

local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight);

local ceiling = display.newRect (0, 0, display.contentWidth, 1);

– Add physics to the walls. They will not move so they will be “static”

physics.addBody (leftWall, “static”,  { bounce = 0.1 } );

physics.addBody (rightWall, “static”, { bounce = 0.1 } );

physics.addBody (ceiling, “static”,   { bounce = 0.1 } );

local function startGame()

– 3. Create a balloon, 25 pixels by 25 pixels

local myBalloon = display.newImageRect(“images/balloon.png”, 25, 25);

– 4. Set the reference point to the center of the image

myBalloon:setanchorpoint(display.CenterReferencePoint);

– 5. Generate balloons randomly on the X-coordinate

myBalloon.x = Random(50, _W-50);

– 6. Generate balloons 10 pixels off screen on the Y-Coordinate

myBalloon.y = (_H+10);

– 7. Apply physics engine to the balloons, set density, friction, bounce and radius

physics.addBody(myBalloon, “dynamic”, {density=0.1, friction=0.0, bounce=0.9, radius=10});

    – Allow the user to touch the balloons

function myBalloon:touch(e)

– If time isn’t up then play the game

if (timeLeft ~= false) then

– If the player is ready to play, then allow the balloons to be popped

if (playerReady == true) then

if (e.phase == “ended”) then

– Play pop sound

audio.play(balloonPop);

– Remove the balloons from screen and memory

removeBalloons(self);

end

end

end

end

– Increment the balloons variable by 1 for each balloon created

balloons = balloons + 1;

– Add event listener to balloon

myBalloon:addEventListener(“touch”, myBalloon);

        – If all balloons are present, start timer for totalTime (10 sec)

if (balloons == numBalloons) then

gameTimer = timer.performWithDelay(1000, countDown, totalTime);

else

– Make sure timer won’t start until all balloons are loaded

playerReady = false;

end

end

– 8. Create a timer for the game at 20 milliseconds, spawn balloons up to the number we set numBalloons

gameTimer = timer.performWithDelay(20, startGame, numBalloons);

“setanchorpoint” is not a valid command. That is why it comes up as ‘nil’. The answers are already in the posts above, so make sure you read them carefully!

setReferencePoint has been outdated 

Use anchor points instead

screenText.anchorX = 0 

screenText.anchorY = 0 

this will place your reference point to top left

if you want bottom left, then :

screenText.anchorX = 0

screenText.anchorY = 1 

https://coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/

Can u please help me out ??? Where all I need to do replace ??? With reference to the attached file…

Instead of: (in other words remove this line)

screenText:setReferencePoint(display.BottomLeftReferencePoint);

and in its place write:

screenText.anchorX = 0&nbsp; -- 0 is left, 0.5 is center, 1 is right screenText.anchorY = 1 -- 0 is top, 0.5 is center, 1 is bottom

But you need to understand what this is about.  In Corona all display objects are basically rectangles. While circles and lines are not rectangles, they still have a bounding box making them a virtual rectangle.

By default Corona SDK with Graphics 2.0 (today’s standard) every display object if you don’t make changes, has their .x and .y mean the center of the object. That is you position everything by its center. In really old version of Corona SDK, what we call Graphics 1. Some objects were positioned assuming .x and .y were the top left corner of the rectangle. Others were centered. There was no consistency.

In both cases, Graphics 1 and today’s Graphics 2, we allowed you to change the rules on where an object was drawn. Graphics one used :setReferencePoint() and you could provide 9 basic locations like display.TopCenterReferencePoint or in your example display.BottomLeftReferencePoint. If you set .x and .y to 100 and 100, the bottom left point of the box would be at 100, 100.

Graphics 2.0 got rid of ReferencePoints and introduced .anchorPoints (.anchorX and .anchorY). By setting these to a value between 0 and 1 you could put the .x and .y value to be any where within the bounding box and a later update allows for negative numbers and numbers greater than one that lets you put the .x and .y outside the box.

Why would you want to do this?  If you’re creating a bunch of display.newTextObjects and you want them all to left-align you can change the .anchorX to 0 and now they will all align nicely. Want to position something at the bottom of the screen?

object.y = display.actualContentHeight

object.anchorY = 1

Rob

still the error is their in 146 line 

as setanchopoint(nil)

– Hide status bar

display.setStatusBar(display.HiddenStatusBar);

– Display a background image

–[[ Here we are inserting

a background image of clouds --]]

local background = display.newImage(“images/clouds.png”);

– Generate Physics Engine

local physics = require(“physics”);

– 1. Enable drawing mode for testing, you can use “normal”, “debug” or “hybrid”

physics.setDrawMode(“normal”)

– 2. Enable multitouch so more than 1 balloon can be touched at a time

system.activate(“multitouch”);

– 3. Find device display height and width

_H = display.contentHeight;

_W = display.contentWidth;

– 4. Number of balloons variable

balloons = 0;

– 5. How many balloons do we start with?

numBalloons = 100;

– 6. Game time in seconds that we’ll count down

startTime = 20;

– 7. Total amount of time

totalTime = 20;

– 8. Is there any time left?

timeLeft = true;

– 9. Ready to play?

playerReady = false;

– 10. Generate math equation for randomization

Random = math.random;

– 11. Load background music

local music = audio.loadStream(“sounds/music.mp3”);

– 12. Load balloon pop sound effect

local balloonPop = audio.loadSound(“sounds/balloonPop.mp3”);

– Create a new text field using native device font

local screenText = display.newText("…Loading Balloons…", 0, 0, native.systemFont, 16*2);

screenText.xScale = 0.5

screenText.yScale = 0.5;

– Change the center point to bottom left

screenText.anchorX = 0

screenText.anchorY = 0

– Place the text on screen

screenText.x = _W / 2 - 210;

screenText.y = _H - 20;

– Create a new text field to display the timer

local timeText = display.newText("Time: "…startTime, 0, 0, native.systemFont, 16*2);

screenText.anchorX = 0.5

screenText.anchorY = 0.5;

timeText.x = _W / 2;

timeText.y = _H - 20;

local gameTimer;

– Did the player win or lose the game?

local function gameOver(condition)

– If the player pops all of the balloons they win

if (condition == “winner”) then

screenText.text = “Amazing!”;

– If the player pops 70 or more balloons they did okay

elseif (condition == “notbad”) then

screenText.text = “Not too shabby.”

– If the player pops less than 70 balloons they didn’t do so well

elseif (condition == “loser”) then

screenText.text = “You can do better.”;

end

end

– Remove balloons when touched and free up the memory they once used

local function removeBalloons(obj)

obj:removeSelf();

– Subtract a balloon for each pop

balloons = balloons - 1;

– If time isn’t up then play the game

if (timeLeft ~= false) then

– If all balloons were popped

if (balloons == 0) then

timer.cancel(gameTimer);

gameOver(“winner”)

elseif (balloons <= 30) then

gameOver(“notbad”);

elseif (balloons >=31) then

gameOver(“loser”);

end

end

end

local function countDown(e)

– When the game loads, the player is ready to play

if (startTime == totalTime) then

– Loop background music

audio.play(music, {loops =- 1});

playerReady = true;

screenText.text = “Hurry!”

end

– Subtract a second from start time

startTime = startTime - 1;

timeText.text = "Time: "…startTime;

– If remaining time is 0, then timeLeft is false

if (startTime == 0) then

timeLeft = false;

end

end

– 1. Start the physics engine

physics.start()

– 2. Set gravity to be inverted

physics.setGravity(0, -0.4)

–[[ Create “walls” on the left, right and ceiling to keep balloon on screen

display.newRect(x coordinate, y coordinate, x thickness, y thickness)

So the walls will be 1 pixel thick and as tall as the stage

The ceiling will be 1 pixel thick and as wide as the stage

–]]

local leftWall = display.newRect (0, 0, 1, display.contentHeight);

local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight);

local ceiling = display.newRect (0, 0, display.contentWidth, 1);

– Add physics to the walls. They will not move so they will be “static”

physics.addBody (leftWall, “static”,  { bounce = 0.1 } );

physics.addBody (rightWall, “static”, { bounce = 0.1 } );

physics.addBody (ceiling, “static”,   { bounce = 0.1 } );

local function startGame()

– 3. Create a balloon, 25 pixels by 25 pixels

local myBalloon = display.newImageRect(“images/balloon.png”, 25, 25);

– 4. Set the reference point to the center of the image

myBalloon:setanchorpoint(display.CenterReferencePoint);

– 5. Generate balloons randomly on the X-coordinate

myBalloon.x = Random(50, _W-50);

– 6. Generate balloons 10 pixels off screen on the Y-Coordinate

myBalloon.y = (_H+10);

– 7. Apply physics engine to the balloons, set density, friction, bounce and radius

physics.addBody(myBalloon, “dynamic”, {density=0.1, friction=0.0, bounce=0.9, radius=10});

    – Allow the user to touch the balloons

function myBalloon:touch(e)

– If time isn’t up then play the game

if (timeLeft ~= false) then

– If the player is ready to play, then allow the balloons to be popped

if (playerReady == true) then

if (e.phase == “ended”) then

– Play pop sound

audio.play(balloonPop);

– Remove the balloons from screen and memory

removeBalloons(self);

end

end

end

end

– Increment the balloons variable by 1 for each balloon created

balloons = balloons + 1;

– Add event listener to balloon

myBalloon:addEventListener(“touch”, myBalloon);

        – If all balloons are present, start timer for totalTime (10 sec)

if (balloons == numBalloons) then

gameTimer = timer.performWithDelay(1000, countDown, totalTime);

else

– Make sure timer won’t start until all balloons are loaded

playerReady = false;

end

end

– 8. Create a timer for the game at 20 milliseconds, spawn balloons up to the number we set numBalloons

gameTimer = timer.performWithDelay(20, startGame, numBalloons);

“setanchorpoint” is not a valid command. That is why it comes up as ‘nil’. The answers are already in the posts above, so make sure you read them carefully!