How can I put an image as background?
What I have tried is to create a Draw2DSprite with my texture storing the image I want for the background, and then using the draw2D.drawSprite(sprite) method.
The problem is that the image doesn´t fill the entire game window.
Also, I want to know if there is a way to put that background without calling the draw2D.drawSprite(sprite) method in each frame.
This is the result I get so far:
And this is my code:
var backgroundSprite;
var backgroundTexture = graphicsDevice.createTexture({
src: "img/BackGround2.jpg",
mipmaps: true,
dynamic: false,
x: 500,
y: 500 ,
onload: function(texture) {
if (texture) {
backgroundSprite = Draw2DSprite.create({
texture: texture,
});
}
}
});
function tick()
{
if (graphicsDevice.beginFrame())
{
draw2D.begin();
if (backgroundSprite)
draw2D.drawSprite(backgroundSprite);
draw2D.end();
//graphicsDevice.clear([1.0, 1.0, 1.0, 1.0], 1.0, 0.0);
graphicsDevice.endFrame();
}
}
Thanks in advance for your answers !!!