Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Path2D:setTexture() — Gideros Forum

Path2D:setTexture()

totebototebo Member
edited July 2016 in General questions
Is Path2D:setTexture() likely to be included in the next build?
My Gideros games: www.totebo.com

Comments

  • totebototebo Member
    I tested it, and it loads the texture but it doesn't repeat. I think this is a hint. ;)

    "Sets texture for fill (Not implemented yet)"
    My Gideros games: www.totebo.com
  • hgy29hgy29 Maintainer
    It ought to work, the documentation is outdated on that point. Did you set your texture to repeat mode ?
  • totebototebo Member
    Yeah, I did a straight swap for the code I use with Shape, where the textures are repeated.
    My Gideros games: www.totebo.com
  • hgy29hgy29 Maintainer
    Ok, I'll have a look at the code then, I was sure it was working...
  • totebototebo Member
    edited August 2016
    Maybe check my code first (crate.png is probably not power of 2, but you get the idea). Cool sharing!






    (not sure why the standard example comes up when sharing the code: http://giderosmobile.com/code/output/MoLbJdwyd2zjU3SFi433anLEyn7dR1vN)
    --Banana shape, SVG path format
    local banana="M8.64,223.948c0,0,143.468,3.431,185.777-181.808c2.673-11.702-1.23-20.154,1.316-33.146h16.287c0,0-3.14,17.248,1.095,30.848c21.392,68.692-4.179,242.343-204.227,196.59L8.64,223.948z"
    p=Path2D.new()
    p:setSvgPath(banana) --Set the path from a SVG path description
    p:setLineThickness(5) -- Outline width
    p:setFillColor(0xFFFF80,0.7) --Fill color
    p:setLineColor(0x404000) --Line color
    p:setAnchorPosition(100,100)
    p:setPosition(100,100)
    stage:addChild(p)
     
    local texture = Texture.new("crate.png", true, {wrap = Texture.REPEAT})
    p:setTexture( texture )
    My Gideros games: www.totebo.com
  • Can I confirm this as not working as it should and add to Git? Or is it working as it should and if so is my code wrong?
    My Gideros games: www.totebo.com
  • NatWobbleNatWobble Member
    edited August 2016
    Hi @hgy29

    I tried rounding the corners on a photo and had an issue too. The texture is a 140 x 140 png and the path2d rounded rectangle is 140 x 140 too, but I get this strange effect:

    image

    I know it isn't a power of 2 image, but no wrapping is required.
    I tried wrap, no wrap, filtered, unfiltered etc but the result is the same.
  • If it is a texture I believe it has to be power of 2 regardless of whether it's repeated or not.

    My issue is different; a 128x128px image used as a texture of a Path2D shape doesn't repeat, but it repeats fine as a texture of a Shape.
    My Gideros games: www.totebo.com
  • SinisterSoftSinisterSoft Maintainer
    edited August 2016
    So with Path2D you have found that textures don't wrap repeat ?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • n1cken1cke Maintainer
    Yes, and it seems they always fit incorrectly into Path2D.
  • OK, confirmed everything is fine at 128x128. Thanks
  • Sorry @sinistersoft, yes, textures in Path2D are loaded, but they don't repeat.
    My Gideros games: www.totebo.com
  • hgy29hgy29 Maintainer
    Accepted Answer
    @totebo,
    Sorry for the delay replying, I am on holidays (until monday) and didn't find enough time to check your issue with Path2D.

    Path2D makes the texture fill the entire shape by default, whatever its size is. There is bug in that textures must be a power of two to fit correctly, and I just fixed it, however this wasn't your case.

    If you want to tile your textures multiple times, you need to pass a texture transform matrix as second parameter to setTexture, ex:
    local scl=Matrix.new()
    scl:setScale(1/5) --Scale down by 5, so that the five textures unit fits in width and height
    p:setTexture( texture,scl )
    This works for me, can you confirm it does for you too ?
  • totebototebo Member
    edited August 2016
    Yes, this magically works! Not quite sure why, wouldn't mind a bit of documentation. :)

    Attached a test project in case anyone is reading this and want to see it in action.

    ps. Help much appreciated. I am also on holiday, but trying to squeeze in a little Gideros fun time here and there too. :)
    zip
    zip
    test.zip
    3K
    My Gideros games: www.totebo.com
Sign In or Register to comment.