Character's shadow

  • #1, by ke4Sunday, 10. May 2015, 12:06 9 years ago
    Hi,

    I was trying to make shadow for the main character somehow through Visionaire, i know it could be done simply if all the animations had shadow inside, but it would be too much work to change it now...

    this is what i've done

    function setCharacterShadow()
    local position
    position = game:getLink(VGameCurrentCharacter):getPoint(VCharacterPosition)
    getObject("Characters[shadow]"):setValue(VCharacterPosition, position)
    end
     
    registerEventHandler("mainLoop", "setCharacterShadow")
    


    It works, but the problem is that the shadow is over the main character ( instead of under ) can i edit the position what i got to i could set a bit different Y position to get the align right?

    Next thing is that i have to set in every scene "if shadow is on scene" action part, which doesn't look much as a good solution..
    Do you have experience with using shadow?

    PS: It's ok to have a bouch of loops in the game, won't be that slowing down the game?

    Thanks for help.

    Key Killer

    810 Posts


  • #2, by afrlmeSunday, 10. May 2015, 13:42 9 years ago
    Offset y by 10 pixels or so... wink

    local pos, scn
    
    function setCharacterShadow()
     if game.CurrentScene:getName() == game.CurrentCharacter.Scene:getName() and game.CurrentScene:getName() == Characters["shadow"].Scene:getName() then
      pos = game.CurrentCharacter.Position
      Characters["shadow"].Position = { x = pos.x, y = (pos.y - 10) }
     end
    end
    
    registerEventHandler("mainLoop", "setCharacterShadow")
    


    Try that. The loop will only update if both characters are on the current scene.

    Imperator

    7278 Posts

  • #3, by ke4Sunday, 10. May 2015, 15:02 9 years ago
    Oh great! Now the shadow is behind the character :-)

    With the "if shadow is on scene" a meant that when i go to another scene the character shadow is not going with me.

    if game.CurrentScene:getName() != Characters["shadow"].Scene:getName() then
    -- set Shadow to game.CurrentScene
    

    Key Killer

    810 Posts

  • #4, by afrlmeSunday, 10. May 2015, 15:22 9 years ago
    Ah that is also possible to add to the loop...

    local pos
    
    function setCharacterShadow()
     if Characters["shadow"].Scene:getName() ~= game.CurrentCharacter.Scene:getName() then Characters["shadow"].Scene = game.CurrentCharacter.Scene end
     if game.CurrentScene:getName() == game.CurrentCharacter.Scene:getName() and game.CurrentScene:getName() == Characters["shadow"].Scene:getName() then
      pos = game.CurrentCharacter.Position
      Characters["shadow"].Position = { x = pos.x, y = (pos.y - 10) }
     end
    end
    
    registerEventHandler("mainLoop", "setCharacterShadow")
    


    P.S: it's not != in Lua it's ~= for if not. See here for more information about Lua operators.

    Imperator

    7278 Posts

  • #5, by ke4Sunday, 10. May 2015, 15:38 9 years ago
    thanks

    I was looking for some setCharacter function.. and it's
    Characters["shadow"].Scene = game.CurrentCharacter.Scene
    But actually it's not working :/ I'm going to check if everything is ok.

    oh, right i'm still in php.. i'll take a look.

    Key Killer

    810 Posts

  • #6, by afrlmeSunday, 10. May 2015, 16:00 9 years ago
    What do you mean it's not working? Could you check the log file please? There are getObject versions to do the script too. Have you upgraded to the latest build of Visionaire Studio? Should be 4.2, build 1182. If not then your build will probably not like my shorthand Lua script code.

    Once shadow character is on the same scene as the current character, the loop should take care of position automatically.

    Imperator

    7278 Posts

  • #7, by ke4Sunday, 10. May 2015, 16:07 9 years ago
    Yes i updated to 1182. I mean when i go to another scene the shadow is not there. It works in the first scene where the shadow is set manually.

    Key Killer

    810 Posts

  • #8, by afrlmeSunday, 10. May 2015, 16:09 9 years ago
    The loop should update the characters scene. Are there any errors mentioned in the log? Please enable log level = info in the vs options, if not already set.

    Imperator

    7278 Posts

  • #9, by ke4Sunday, 10. May 2015, 16:16 9 years ago
    I'm having issues with the log file, i have info level, i'm sure that i'm looking into correct folder, but the file is completely empty. I tried print something for testing, but it's not there, it seems to be broken somehow, because it works for new created projects.

    Key Killer

    810 Posts

  • #10, by afrlmeSunday, 10. May 2015, 16:40 9 years ago
    try reading it in console (tab) then type: print log

    Imperator

    7278 Posts

  • #11, by ke4Sunday, 10. May 2015, 16:44 9 years ago
    It says failed to open the file.

    Key Killer

    810 Posts