I've been playing around with few projects, and I fixed a code in the way I do need it, but somehow it prints like a "lines" after the bottom or top or the picture is reached( I don't know, it's just the lines). What's the best way to remove the horizontal lines from moving background?
main.lua
sceneManager = SceneManager.new({
--start scene
["back"] = back,
["BGpara"] = BGpara,
})
--add manager to stage
stage:addChild(sceneManager)
--start start scene
sceneManager:changeScene("back", 1, SceneManager.moveFromBottom, easing.outBack) |
BGpara.lua
BGpara = Core.class(Sprite)
function BGpara:init(bgs, bgspeed)
self.bg1 = Bitmap.new(Texture.new(bgs.bg1),true)
self.bg2 = Bitmap.new(Texture.new(bgs.bg1),true)
self.bgFarY=0
self.bgNearY=0
self.bgspeed = bgspeed
self:addChild(self.bg1)
self:addChild(self.bg2)
self:addEventListener(Event.ENTER_FRAME, self.BGparas, self)
end
function BGpara:BGparas(event, container)
self.bgFarY = (self.bgFarY or 0) - ((self.bgspeed or 4.0) / 4)
self.bgNearY = (self.bgNearY or 0) - ((self.bgspeed or 4.0))
self.newFarY = self.bg1:getWidth() -(-self.bgFarY)
if self.newFarY <=0 then
self.bgFarY = 0
self.bg1:setX(self.bgFarY)
else
self.bg1:setX(self.bgFarY)
self.bg2:setX(self.newFarY)
end
end
function BGpara:setSpeed(bgspeed)
self.bgspeed = bgspeed
end
function BGpara:getSpeed()
return self.bgspeed
end |
back.lua
back = Core.class(Sprite)
application:setKeepAwake(true)
application:setOrientation("landscapeLeft")
local bgs = {
bg1 = "bg1.png",
}
local bg = BGpara.new(bgs, 15)
stage:addChild(bg) |
Comments
Please correct me if I am wrong:
you are doing a horizontal parallax scrolling background, with 2 layers (2 textures: one near moving quick, the other far which moves slow).
When and where does the white line appear? Does it happen when the textures overlap? Are you sure it's not a wrong "cut" of the "nearest" png?
I can't tell without seeing the images: could you post those too?
https://uploadfiles.io/4d0a61
No, I want to make a vertical parallax scrolling background, for now just with 1 texture.
In my opinions the line appears after the image is scrolled down. Maybe that's the problem, I'm just trying to make it with one picture for now
I assumed it was horizontal scrolling because X and width are processed in your code, even if you call your variables farY and nearY
If you don't have the white line in your png, it could happen due to some slowdown moving the two images together: try overlapping them by 4 pixels (which is your default scroll speed)
Okei, I'll try to overlap them by 4 pixels, one momento
Your issue is in the png, you have 2 translucent lines of pixels on both sides.
try using the attached image, I just cut them out
[edit: P.S. this is horizontal scrolling to me ]
Likes: tytadas