F
F
Ferret Common2018-02-23 15:29:26
JavaScript
Ferret Common, 2018-02-23 15:29:26

How to output some info to the canvas every time the function is executed?

The point is this. I am writing a game. I'm making a timer. And I need a tag that will display time in the canvas. Here is the script:

var gameField = document.getElementById("gameField");
var graphics = gameField.getContext("2d");

var m = 1;
var s = 31;
var a = 1;
var b = 31;

function timer() {
    if ((s > 0) && (m >= 0)) {
        s = b - 1;
        b = s;
        document.write(a + ':' + b);
    }
    if ((s = 0) && (m > 0)) {
        s = 59;
        m = a - 1;
        a = m;
        document.write(a + ':' + b);
    }
    if ((s = 0) && (m = 0)) {
        alert ('Время закончилось');
    }
}

setInterval(timer, 1000);

Ugly it turns out with document.write. And one more question: time doesn't move anywhere for me. I typed in 1:31, document right outputs 1:30 and doesn't output anything else. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2018-02-23
@twobomb

It's strange how you make a game if you can't even display the text. Can it be like this

S
Stanislav Makarov, 2018-02-23
@Nipheris

strokeText

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question