Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Something is wrong with my code — Gideros Forum

Something is wrong with my code

tytadastytadas Member
edited December 2016 in General questions
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

  • can you post a screenshot/video of the issue?
  • Yes, I see the line, but I am still not sure about what should happen and which shapes the png have :)

    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?
  • I think it would be better if you take a look at my full project file.
    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
  • there are no images in your file :)
    I assumed it was horizontal scrolling because X and width are processed in your code, even if you call your variables farY and nearY :D

    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)
  • I'm sorry, here now I added the image: https://ufile.io/b6d95

    Okei, I'll try to overlap them by 4 pixels, one momento
  • piepie Member
    edited December 2016 Accepted Answer
    @tytadas don't bother, keep the code clean. :)
    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 :D]
    bg1.png
    818 x 640 - 25K

    Likes: tytadas

    bg1.png 24.6K
    +1 -1 (+1 / -0 )Share on Facebook
  • Yea you were right :D But the image scrolls vertically ;p Really Big Thanks for the Help! ;;)
Sign In or Register to comment.