olmamalıdır. Bu yüzden bir HTML5 oyunu yapıyorum ve tuval üzerine düğmeler yapmak istiyorum.Tuval dikdörtgenler x ve y ile aynıdır ama
benim işlevi benim kodunda başka bir yerde, bir düğme yapmak için var 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;
}
Ben iki düğme yapmak -
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);
düğmeleri ayrı ayrı çiziliyor rüzgar
.. ama x ve ys dışarı teselli zaman Kodda ikisi de aynıdır.
ahhhh tamam bu mantıklı. çok teşekkürler. – joe