Hello! I am brand new to Gideros and lua programming for that matter as well. I've tried to place two bitmap images right next to each other but it seems that there is a 1 pixel space between them.
local width
bg = {}
for i = 0, 1 do
bg[i] = Bitmap.new(Texture.new("Images/watertilescaled.png"))
width = bg[i]:getWidth()
bg[i]:setPosition(i * width, 0)
stage:addChild(bg[i])
end
This code builds two images right next to each other, the problem is that they are 1 pixel apart. What I am trying to do in the end is have these two 800x480 images side by side and scrolls through them like a side scroller game. I already have them scrolling as well but when I implement the scrolling effect the gaps between the two bitmaps grow even larger! I've already checked and my images don't have any white space around them so that wouldn't be the problem. Here is the code for the scrolling:
function onEnterFrame(event)
local y, x = accelerometer:getAcceleration()
fx = x*10
fy = (y+0.4)*10
for i = 0, 1 do
bg[i]:setPosition(bg[i]:getX()+fx, bg[i]:getY())
if bg[i]:getX() < -width then
bg[i]:setX(bg[i]:getWidth())
elseif bg[i]:getX() > width then
bg[i]:setX(-bg[i]:getWidth())
end
end
end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
Any idea on what may be going on wrong? or what I may be doing wrong
?
Comments
You can add all bg images to one sprite and then only move that one sprite, all children images will move with it. You'll have to move only one object, thus you ensure that distance between images will be constant
Likes: Blurealms
It looks like your coming from a "C" background, arrays in lua generally start from 1 not 0, in a lot of cases (especially with pre-built libraries and other peoples functions) trying to access element 0 in a table will cause issues.
change the above
Lastly - it might not make too much of an issue or even be relevant but... I'd always try as much as possible to keep your image sizes even rather than allowing odd sizes.
Just my $0.02
Likes: Blurealms
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
ar2rsawseen I actually really like the idea of simply placing the two images onto one sprite! Only question I have is how do you do that? =P Thank you as well!
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps