ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
364 stars 75 forks source link

Question: how to use jaws.Text? #111

Open belen-albeza opened 10 years ago

belen-albeza commented 10 years ago

I'm trying to use jaws.Text, but I cannot make it work and cannot find any example on how to use it :(

Here's what I've tried so far (here's the jsfiddle)

var text;

function setup() {
    text = new jaws.Text({text: "Hello World", x: 10, y:10});
}

function draw() {
    jaws.clear();
    text.draw();
}

jaws.start();

What am I doing wrong? Thanks! :)

ippa commented 10 years ago

Added a jaws.Text to example9, seems to work: http://jawsjs.com/jawsjs/examples/example9.html

Devanon commented 10 years ago

I've got some problems trying to center a Text element in the canvas.

This next line doesn't seem to work, and I think it is valid code: scoreboard = new jaws.Text({text: 'example', x: jaws.width/2, y: jaws.height/2, anchor: 'center'});

The solution was to avoid the use of the anchor tag (Text defaults it to 'top_left'), and center it manually hard coding the x value. Setting the value of y to 'jaws.height/2' worked.

I am not sure if there is a problem in jaws.Text or I am not using it correctly