Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object interaction - Help needed! #52

Open
qsrahman opened this issue Jan 14, 2017 · 0 comments
Open

Object interaction - Help needed! #52

qsrahman opened this issue Jan 14, 2017 · 0 comments

Comments

@qsrahman
Copy link
Contributor

qsrahman commented Jan 14, 2017

I am trying to make a simple game where random numbered squares are displayed and the player click on a square in sequence to make them disappear!. The problem is that if two or more squares overlap and the player click on the top most square all the squares beneath it disappear :(. Here is the test code:

let g = ga(480, 320, setup);
g.start();

function setup() {
    g.backgroundColor = "white";
    g.canvas.style.border = "1px black dashed";

    let numTiles = 10;

    for(let i = numTiles; i >= 1; i--) {
        let shape = g.rectangle(80, 80, 'lightgray', 'black', 1);
        shape.interactive = true;
        let numberText = g.text(i, "24px puzzler", "red");
        shape.addChild(numberText);
        shape.putCenter(numberText, -numberText.width, -numberText.height);

        shape.x = g.randomInt(0, g.canvas.width - shape.width);
        shape.y = g.randomInt(0, g.canvas.height - shape.height);

        shape.press = () => {
            shape.visible = false;
        }
    }

  g.state = play;  
}

function play() {
  console.log("play");
}

How to stop the lower squares from disappearing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants