Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Bitmap setPosition off? — Gideros Forum

Bitmap setPosition off?

BlurealmsBlurealms Member
edited April 2012 in General questions
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

  • ar2rsawseenar2rsawseen Maintainer
    Just a tip for the scrolling part
    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

    +1 -1 (+1 / -0 )Share on Facebook
  • Also a comment re your code,
    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
    for i=0,1 do
    to
    for i=1,2 do
    Also as the original code loads a texture called "watertiledscaled.png", I'd check to make sure that you didn't inadvertently add in an extra transparent pixel when you scaled the image, printing the width (use the the print() function) that Gideros "thinks" the image is and comparing it to what your image editor thinks it is would be useful.

    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

    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
    +1 -1 (+1 / -0 )Share on Facebook
  • BlurealmsBlurealms Member
    edited April 2012
    Ahh thanks techdojo! I'm coming from a java background, but none the less I tend to start at 0 =P My 0's have been changed to 1's! Thank you!

    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!
  • ar2rsawseenar2rsawseen Maintainer
    Something like this would do:
    local sprite = Sprite.new()
    local width = 0
     
    for i = 0, 1 do
       local bg = Bitmap.new(Texture.new("Images/watertilescaled.png"))
       bg:setPosition(i * bg:getWidth(), 0)
       sprite:addChild(bg)
    end
     
    stage:addChild(sprite)
    Then on enter frame you only need to move sprite object
  • My 0's have been changed to 1's!
    Is that an XOR or a binary flip ;)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    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
Sign In or Register to comment.