Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Dynamic Masks — Gideros Forum

Dynamic Masks

OZAppsOZApps Guru
edited February 2012 in General questions
I cannot believe it was there all along...

Here's my little tutorial on this topic really basic.
http://howto.oz-apps.com/2012/02/create-dynamic-masks-gideros-only.html
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

Comments

  • MikeHartMikeHart Guru
    edited February 2012
  • @OZApps, your website is not usable on my iPad, I tap on "Read More" but nothing happens for a little and then Safari crashes.
  • let me check that and see, strange that it should do that...
    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
  • @magnusviri, thanks for that heads up, I had changed some settings for a RSS blog reader widget and changed it to display text upto the jump point, and it is silly in the sense, that it applies that to the whole site, not the RSS Feed. Fixed now, so should not be a problem.
    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
  • ZoytZoyt Member
    Thanks! Nice!
  • This is awsome! Is there any reason we'd want to use a Bitmap over this method of displaying a texture? I almost created my own MaskedBitmap class but I thought this should be part of the official API.

    There was also talk about in this thread:

    http://giderosmobile.com/forum/discussion/comment/3903#Comment_3903

    I have no idea what the issues they are discussing here are. I'm not sure if I should ask in this thread or that one though...
  • I think there is, this masking method is actually a shape that is filled, where as the Bitmap is a direct texture on the screen. So as the older Windows API went, you can BitBlt the bitmap onto the screen, has a lower overhead and if you want to mask the same, then one can use the shape object and fill it with the texture and adjust the texture accordingly, this is a draw method, that has a slightly higher overhead as compared to the direct blitting the bitmap onto the screen.

    I would be curious to know what your approach was, when you say you wrote your own maskedBitmap class.
    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
  • I guess the only problem I can see with this method is it will only act to mask a single texture, not other visible elements, nor groups of elements so, whilst it's definitely useful for simple cases, it doesn't seem to provide what's ultimately needed with either clipping or bitmap masking.
  • Ok, I'll explain why I'm interested in masks. You can make a homemade stereo 3d viewer by putting 2 magnifying glass lenses next to each other like eye glasses and about 3-5 inches away from a mobile phone (I used a cardboard box and tape to keep it all together). I've been playing with creating stereo split parallel views by drawing something twice, slightly offset on each side of the screen. To get this working with images, I need to have each side of the screen clip down the middle so that images from one side don't cross over to the other side.

    I was thinking of making a custom MaskedBitmap class so that it autosized to the image, then if the image was ever moved to the middle, it would auto clip itself so it never crossed the boundary.

    I'm thinking this would just be a messy hack and I should just wait for official clipping support and work on other things until then.

    Likes: DRS

    +1 -1 (+1 / -0 )Share on Facebook
  • MauMauMauMau Member
    edited July 2013
    Just migrated to Gideros and found this feature painfully missing -at least I could not find anything about a masking feature in the docs :-(

    As moopf explained above, the workaround explained above does not work with groups of images or combined elements, so it's funny to play with, but by no means a replacement for a missing masking feature.
  • @MauMau, meanwhile combined with rendertarget, now you can mask combined elements as well i think.
    just make your complicated sprite hierarchy with the elements, draw it on a rendertarget and then draw a shape using this rendertarget as texture./
  • local x,y,w,h = MySprite:getBounds(stage)
    local Tex = RenderTarget.new(w, h)
    local Img = Bitmap.new(TextureRegion.new(Tex,0,0,w,h))
    Img:setPosition(50,50)
    stage:addChild(Img)
     
    Tex:clear(0x000000, 1) 
    Tex:draw (MySprite)
    The code above only results in a black square where Img should be. Any ideas why?

    MySprite is a complex sprite with bitmaps, sprites and texts within.

  • Hm, I can't get the RenderTarget thing to work here (Windows, Gideros 2013.06.3) -it results in a black square only :-(

    Is there a *working* RenderTarget code snippet anywhere that I can test to verify if this feature works on my machine?
  • @MauMau
    You might be misinterpreting the internal Sprite positioning or getBounds method, so for example, if I do this:
    MySprite = Sprite.new()
    local bmp = Bitmap.new(Texture.new("ball.png", true))
    MySprite:addChild(bmp)
     
    local x,y,w,h = MySprite:getBounds(stage)
    local Tex = RenderTarget.new(w, h)
    local Img = Bitmap.new(TextureRegion.new(Tex,0,0,w,h))
    Img:setPosition(50,50)
    stage:addChild(Img)
     
    Tex:clear(0x000000, 1) 
    Tex:draw (MySprite)
    It works as expected, but if change bmp position to 100,100 like this:
    MySprite = Sprite.new()
    local bmp = Bitmap.new(Texture.new("ball.png", true))
    bmp:setPosition(100, 100)
    MySprite:addChild(bmp)
     
    local x,y,w,h = MySprite:getBounds(stage)
    local Tex = RenderTarget.new(w, h)
    local Img = Bitmap.new(TextureRegion.new(Tex,0,0,w,h))
    Img:setPosition(50,50)
    stage:addChild(Img)
     
    Tex:clear(0x000000, 1) 
    Tex:draw (MySprite)
    it will display black rectangle, because it will display only w width and h height from 0,0 coordinate, and coordinate 100,100 is out of that visible area.

    So most probably your internal objects inside MySprite are positioned outside this visible area. You could check it by increasing w and h values, for example like this:
    local x,y,w,h = MySprite:getBounds(stage)
    local Tex = RenderTarget.new(x+w, y+h)
    local Img = Bitmap.new(TextureRegion.new(Tex,0,0,x+w,y+h))
    If you are interested as to why it is a black square, then because you clear it with black color here:
    Tex:clear(0x000000, 1)
    Hope that helps ;)
  • Ah, thanks for clarifying this. It indeed works if I set the position of MySprite to 0,0

    So the sprite that should be drawn to a render target always needs to be positioned at 0,0?

  • ar2rsawseenar2rsawseen Maintainer
    edited November 2013
    From the texture stand of point yes, everything in texture should be absolutely positioned, So for RenderTarget you must have all the width from 0 to you position + width
    but it does not mean you can't have such offsets, as you can again apply the offset like this (taking only needed texture region):
    local Img = Bitmap.new(TextureRegion.new(Tex,x,y,w,h))
  • Now I got it -thanks, ar2rsawseen!!! :-)


Sign In or Register to comment.