Can I know if a scene object is currently shown on the screen?

  • #1, by hallinniklasMonday, 12. January 2015, 11:23 10 years ago
    So, I have this scene, which is bigger than a screen, and so when the character moves to the side the camera pans along to show the rest of the scene. Simple stuff.

    Now I have an object on the far side of the scene, so that it is not visible to the player when the scene starts. What I want to do is to play a sound the instant the camera pans over this object and it appears on the screen.

    Any ideas on how I can make this happen?

    I have tried a solution using Action Areas, so that when the player walks close to this object the sound is played. But it is really tricky to get the camera and the walking character to sync up, and the sound if often played at the wrong time.

    What I am really looking for is some what of measuring the cameras position, and not the characters position.

    I found this lua thingy called:
    VGameScrollPosition
    

    which seems to be what I am looking for, but I have no idea how to turn that into an if-statement, or even if I can do if-statements that are checked on every update.

    Does anyone have any ideas on what I can do to make this happen?

    Thank you very much

    Newbie

    15 Posts


  • #2, by afrlmeMonday, 12. January 2015, 11:43 10 years ago
    I think by default the scroll edge (the distance from scene edge that causes viewport to scroll when character surpasses said distance) is either 50px or 100px (I forget which), which means if you were to use the action area system that you would need to create the action area at least the width of your game default resolution width + the scroll edge distance to correctly capture the character at the time you want the sound to play, in theory.

    Alternatively, you could create a loop at begin of scene to check if game scroll position equals a specific distance away from the object. You would probably have to specify the coordinate of the object too, unless it is an animation which will allow you to automatically return the top left pixel of said animation.

    Could you give me a few more details on exactly what you are wanting to do & why please?

    Imperator

    7278 Posts

  • #3, by hallinniklasMonday, 12. January 2015, 19:27 10 years ago
    Hello there.

    This is a bit spoiler-y, but by almost the end of the game I'm working on, you walk through this room and all of a sudden you find this strange woman just sitting on the bed, in what is probably the biggest climax of the whole story. It would be cool if I could amplify the effect by playing a sound (dum-duummm!) the very instant this woman appears on the screen, but I'm having a hard time matching the sound to the event.

    I could almost make it to some sort of cut scene, actually. If you move to a certain point in the room, you will lose control over the character and the camera would pan the rest of the way, while the sound effect is playing. And then, when the sound is over, the control returns to the player.

    I'm attaching an image of what the scene looks like.

    (removed)

    Newbie

    15 Posts

  • #4, by afrlmeMonday, 12. January 2015, 20:00 10 years ago
    Hmm the cut-scene method sounds very plausible.

    Is the woman sat there throughout the entire scene or does she just appear?

    You could have sent me a message instead if you didn't want to share the screens/info in the message. wink

    Ok here's something you could do... (I'm assuming you are using the latest version of VS)

    1. create a condition that you will use to determine if even has been triggered or not & give it a unique name.

    2a. In an at begin of scene action action add an if condition "unique_condition" is false

    2b. Then create an execute a script action part containing...
    registerEventHandler("mainLoop", "checkScrollPosLoop")
    


    2c. Add an End If action part.

    3. Now you need to create an new script inside of the script section of the editor...
    local targ = 100 -- replace 100 with actual x coordinate where you want sound to trigger.
    local range = 25
    
    function checkScrollPosLoop()
     if game.ScrollPosition.x = (targ - range) then
      startAction("Actions[scary_woman_sound]") -- start action that contains play sound action part
      unregisterEventHandler("mainLoop", "checkScrollPosLoop") -- kill the loop
     end
    end
    


    4. Now you need to create a called by other action action somewhere & name it scary_woman_sound. Add a play sound action part to this.

    That should be it, I think.

    Imperator

    7278 Posts

  • #5, by hallinniklasMonday, 12. January 2015, 20:03 10 years ago
    Hey, cool!

    I'll look into that, and see what happens.

    Thank you for your help!

    Newbie

    15 Posts

  • #6, by afrlmeMonday, 12. January 2015, 20:44 10 years ago
    No problem. wink

    I have no idea if it will work or not as I wrote the post, scripts & action parts, off the top of my head.

    Imperator

    7278 Posts