Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Tutorial: How to create a spot light — Gideros Forum

Tutorial: How to create a spot light

MikeHartMikeHart Guru
edited March 2012 in Step by step tutorials
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

Likes: atilim

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • GregBUGGregBUG Guru
    edited December 2011
    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
  • gorkemgorkem Maintainer
    Ops, we have to remove it.. Sorry, it is only for subscribers! :P
  • No Gorkem!!!!

    What does the smiley face mean? (ndoss is hoping gorkem is kidding)
  • gorkemgorkem Maintainer
    Kidding to the limits :-h
  • atilimatilim Maintainer
    @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 :)
  • MikeHartMikeHart Guru
    edited December 2011
    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?
  • atilimatilim Maintainer
    edited March 2012
    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.
  • atilimatilim Maintainer
    edited March 2012
    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 Guru
    edited March 2012
    Project updated and attached to the top post.

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • 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.
  • evsevs Member
    @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
  • evsevs Member
    @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
  • evsevs Member
    @techdojo The demo has been updated by Mike


    cheers

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

    Now where's that straitjacket :P


    cheers

    evs
    zip
    zip
    SpotLight.zip
    110K
  • @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
    zip
    zip
    inspect.lua.zip
    2K
  • evsevs Member
    @iancha Thanks, I've already got inspect.lua though :D

    I also use this...

    cheers

    evs
    zip
    zip
    dump.lua.zip
    694B
Sign In or Register to comment.