Quick Links: Gideros Home | Download Gideros | Developer Guide
Tutorial: How to create a spot light - Gideros Forums
Tutorial: How to create a spot light
  • MikeHartMikeHart +1 -1 (+1 / -1 )
    Hi folks,

    while analyzing the LUA tables of a running gideros script, I stumbled over a nice feature. The ability to set the blend mode for a sprite. AWESOME!!!

    Here is a little script that shows a spot light running over the gideros logo.

    Enjoy
    Michael
    SpotLight_Gideros.zip
    47K

    Loves: atilim

    Hates: TheOddLinguist

  • wow! just tested your example on my SGS!!!

    run very very very smooth!
    cool!!!


    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • Nice find!
  • Ops, we have to remove it.. Sorry, it is only for subscribers! :P
    Before starting with Gideros Studio, read our extensive Developer FAQ here
  • No Gorkem!!!!

    What does the smiley face mean? (ndoss is hoping gorkem is kidding)
  • Kidding to the limits :-h
    Before starting with Gideros Studio, read our extensive Developer FAQ here
  • @MikeHart I'm amazed! :-O :)

    The main reason why this isn't documented is that I was planning to replace it with an easier one like:

    sprite:setBlendMode(ADD) or
    sprite:setBlendMode(MULTIPLY)

    About glBlendFunc, even though there are many combinations that you can use, only a few of them are common and useful :)
  • As long as there is a blending functionality, i am happy. But your approach is a better one as it's easier to understand. Please add SUB to it too.
  • This code doesn't work anymore.

    main.lua:43: attempt to index global 'BlendFactor' (a nil value)

    Is that because it is being worked on?
  • Hi,

    Undocumented BlendFactor and setBlendFunc was removed and Sprite:setBlendMode was added instead. I can modify the @MikeHart's example and post a new one here.
  • In fact, there is no need to post a new version. You should change line 43 from
    logo:setBlendMode(BlendFactor.DST_COLOR, BlendFactor.ZERO)

    to
    logo:setBlendMode(Sprite.MULTIPLY)


    :)
  • MikeHartMikeHart +1 -1 (+1 / -0 )
    Project updated and attached to the top post.

    Loves: atilim

  • I noticed in the main.lua file there is reference to speedX, speedY, dirY, dirX. However, I can't find a reference to these anywhere in the API docs. I looked to see if "mask" was more than a bitmap (perhaps a class with these field), but it isn't.
  • @onsdesic they're just variables defined earlier in the file not actually part of mask (Bitmap)
    mask.speedX = 2
    mask.speedY = 1
    mask.dirX=1
    mask.dirY=1


    NOTE: if they were part of mask (Bitmap) it would be something more like mask:setSpeedX(2) etc


    cheers

    evs
  • evs,

    Now I'm really confused. maybe this is something in Lua I don't understand. So when you type "mask.speedX = 2", you are actually creating a new variable?? I thought you would have to use "local" or something like that. So you can just create variables on the fly? This shows how new I am to lua.
  • Yes, you can create any variable on the fly.
  • When you type mask.speedX = 2 your actually adding a variable called speedX to the table called mask.

    As Mike said, you can add any variable (or function) to the app (or any table) at any time.

    If you prefix a variable with the word local then it's scope is the current block (chunk) it's defined in, otherwise it becomes a global variable.

    You have to be really careful with languages like lua, because you'll not get any warning if you misspell a variable name or accidentally make a variable global and the bugs that it causes can be VERY hard to track down.

    In a language that was designed to be embedded within another program and used to add scripting functionality to said program you can sort of see why the extra overhead of checking these kinds of things wasn't needed (that's the job of the compiler normally), however as soon as you start to use it for fully fledged app development in it's own right then your out on your own. Proceed with caution! :)
    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
  • @ondesic

    You can use this to look at mask (or any table's) contents to try to understand what's going on under the hood:
    for key, value in pairs(mask) do
     
    print(key, value)
     
    end


    You'll get something like:

    dirX 1
    speedX 2
    speedY 1
    dirY 1
    __userdata userdata: 0x1086985b8

    where __userdata will be the original mask (Bitmap)

    cheers

    evs
  • FWIW - The blend modes that @Atilim mentioned have now been implemented and @MikeHart's original demo should be considered out of date.
    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
  • @techdojo The demo has been updated by Mike


    cheers

    evs
  • This version with sound (courtesy of @gorkem) will drive you up the wall!!!

    Now where's that straitjacket :P


    cheers

    evs
    SpotLight.zip
    110K
  • evs said:

    @techdojo The demo has been updated by Mike


    cheers

    evs



    Thanks evs :)
  • My bad - sorry :(
    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
  • @evs, try this instead:

    local inspect = require 'inspect'
    foo = Sprite.new();
    print (inspect(foo));

    You can see all the goodies inside. I put inspect.lua and other handy utilities in my init.lua for easy maintenance. Thank you @atilim and @MikeHart - I was wondering what those constants were inside Sprite()... great stuff.

    - Ian
    inspect.lua.zip
    2K
  • @iancha Thanks, I've already got inspect.lua though :D

    I also use this...

    cheers

    evs
    dump.lua.zip
    694B

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters