Reputation: 3876
I'm creating simple game using corona.
First thing i'm trying to do is load the background image; but what i got is that, corona simulator show small part of image at the top most left side and the rest of image stay black even if i used all the scaling mode and i'm sure from image size.
Then i added three parameter to the display.newimage
method so i got better situation but i still have a black bar on the left.
My config.lua
application = {
content = {
fps = 60,
width = 320,
height = 480,
scale = "zoomEven",
-- xAlign = "center",
--yAlign = "center",
imageSuffix = {
["@2x"] = 2;
},
},
}
and main.lua
local background = display.newImage("images/clouds.png");
first result on all devices
then what i made to got better result is make this small edit to main.lua
local background = display.newImage("images/clouds.png",230,150, true);
and the second result
Upvotes: 1
Views: 279
Reputation: 3063
display.newImage() by default will want to draw the object at an X, Y of 0,0. This represents the center of the object. You can either change the anchor points as listed above. You can provide an X, Y as parameters to display.newImage() or you can do:
local background = display.newImage("images/clouds.png");
background.x = display.contentCenterX
background.y = display.contentCenterY
I personally prefer this method because you explicitly position the item.
Rob
Upvotes: 1
Reputation: 597
You must modify the anchor property, this property allows you to control the alignment of the object along the x or y direction. By default, new objects have their anchor set to 0.5 corresponds to a center alignment. By setting it to 0 is meaning the left edge of the object.
local background = display.newImage("images/clouds.png");
background.anchorX = 0
background.anchorY = 0
Upvotes: 3