Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
A lil help with images in BHWax — Gideros Forum

A lil help with images in BHWax

SimpleLoopSimpleLoop Member
edited October 2012 in General questions
I am trying to do this to set a tiled image as my views background

self:view():setBackgroundColor(UIColor:colorWithPatternImage(UIImage:imageNamed("Images/leather.png")))

I did not receive an error but the background on the view does not change.
So I tried this

local filename = "Images/leather.png"
print("loading image @ "..filename)
local image = UIImage:imageNamed(filename)
if not image then
print("image failed to load!")
end

And this printed Image failed to load! so I tried "|D|Images/leather.png" and "|R|Images/leather.png" still with no luck.

@bowerandy is this the correct way to do this?
How would I set a UIImage to an image file inside my Gideros Project

Any help appreciated

Comments

  • @SimpleLoop, I haven't got time to try this right now as my son has bashed himself in the eye and I'm off to the doctors but...

    The image you have will be in |R| (if it is included in the Gideros project itself). However, this |R| is a Gideros only naming convention. To convert this to a real full iOS path I have included a function in the original plugin called, getPathForFile(). Try using this to expand the filename you pass to the UIImage.

    If this doesn't work, it might be that UIImage can only load files that are built in to the application resource bundle. I know some Cocoa component can only do this, let's hope UIImage isn't one of them.

    best regards
  • atilimatilim Maintainer
    edited October 2012
    @bowerandy oh! I hope that accident is not serious and your kid gets well soon.
  • bowerandybowerandy Guru
    edited October 2012
    @atilim, yes he's fine. Thanks for asking. Just needed to wait 2hrs in hospital to get it checked out.
    +1 -1 (+1 / -0 )Share on Facebook
  • bowerandybowerandy Guru
    edited October 2012 Accepted Answer
    @SimpleLoop. I have verified that you can use UIImages to load your own image files stored in the |R| and |D| directories. You do have to use the getPathForFile() function and also you need to use imageWithContentsOfFile: (rather than imageNamed:). I think the latter will only find images that are in your iOS bundle resources.

    Here's an example. It doesn't create a tiled background texture, but instead populates an UIImageView.
    local image=UIImage:imageWithContentsOfFile(getPathForFile("|R|Images/uk.png"))
    local imageView=UIImageView:initWithImage(image)
    local imageFrame=BhUIViewFrame.new(imageView, CGRect((768-200)/2, 100, 216, 216))
    self:addChild(imageFrame)
    This code is taken from this demo that shows two UIImageViews (that display UIImages) scrolling in and out of a Gideros scene:


    The demo code is now in an updated version of the BhWax repository.

    best regards
  • @bowerandy glad your son is ok.
    Sorry about the slow response, hadn't been on the forums.
    Wow awesome, that works perfectly.

    I can't thank you enough I would've been stuck on this for hours.
Sign In or Register to comment.