ちょっと私はHTML5のゲームを作っていますし、キャンバス上にボタンを作りたいと思っています。キャンバスの四角形はxとyは同じですが、同じではありません。
私は2つのボタンにする私のコードのどこか、ボタンを作るために私の機能です Button = function(text, x, y, width, height){
self.x = x;
self.y = y;
self.width = width;
self.height = height;
self.createButton = function(){
ctx.save();
ctx.fillStyle = "yellow";
ctx.fillRect(self.x, self.y, self.width, self.height);
ctx.fillStyle = "black";
ctx.font = '30px Arial';
ctx.fillText(self.text, self.x, self.y + (self.height/2));
ctx.restore();
}
self.createButton();
return self;
}
-
var button1 = Button('Button 1', WIDTH/2, HEIGHT/2, 200, 40);
var button2 = Button('Button 2', WIDTH/2, (HEIGHT/2) + 50, 200, 40);
console.log('button1 x: ', button1.x);
console.log('button1 y: ', button1.y);
console.log('button2 x: ', button2.x);
console.log('button2 y: ', button2.y);
ボタンが個別に描かれている羽目になる..しかし、私は、xとYSを慰めるときにコードではまったく同じです。
ああこれは意味があります。どうもありがとう。 – joe