Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how to tile a background texture — Gideros Forum

how to tile a background texture

james23james23 Member
edited May 2013 in General questions
Tried this as per the documentation but it doesn't work. Not sure if I'm using it correctly or there's something I'm not doing.

local background = Bitmap.new(Texture.new("bg.jpg", true, {wrap = Texture.REPEAT}))
stage:addChild(background)

Comments

  • brigosxbrigosx Member
    This is how I do in my game in order to repeat the background image vertically:

    local text = Texture.new("images/roadmap.png", false, {wrap = Texture.REPEAT})
    local regi = TextureRegion.new(text, 0, 0, text:getWidth(), application:getDeviceHeight())

    local rmap = Bitmap.new(regi)
    self:addChild(rmap)

    I think that by replacing the "text:getWidth()" with "application:getDeviceWidth()" you will be able to produce the effect you want. For larger resolutions apply the appropriate width/height.
  • ar2rsawseenar2rsawseen Maintainer
    @james23 yes and the other way would be:
    local texture = Texture.new("images/crate.png", true, {wrap = Texture.REPEAT})
    local shape = Shape.new()
    shape:setFillStyle(Shape.TEXTURE, texture) 
    shape:moveTo(0,0)
    shape:lineTo(application:getDeviceWidth(), 0)
    shape:lineTo(application:getDeviceWidth(), application:getDeviceHeight())
    shape:lineTo(0, application:getDeviceHeight())
    shape:lineTo(0,0)
    shape:endPath()
    stage:addChild(shape)
    In this case the texture should be in ^2 size like 64x64px or 128x128px, etc
Sign In or Register to comment.