Creeps Compilation's Forum Posts

  • Hello Skymen,

    I have an important Construct 2 project going that requires the use of a cell phone or tablet

    camera. In many cases, poor lighting requires the use of the cell phone or tablet FLASHLIGHT.

    The Construct 2 "User Media" plugin works great, except, when I go to my cell phone menu and

    activate the built in FLASHLIGHT feature within the cell phone, this turns OFF the Construct 2

    "User Media" camera itself. I am not able to get BOTH working together.

    This has been very frustrating and I have posted several forum requests for help, without a real

    solution. Including to Scirra direct, asking them to ADD the FLASHLIGHT FLASH ON and OFF function

    to the existing "User Media" plug in.

    What I need is ANY solution, including script I can run using the "Browser" plugin, which will allow

    my project to TUNR ON and OFF the cell phone or tablet FLASHLIGHT without conflicting with the Construct 2 "User Media" camera plugin.

    construct.net/en/forum/construct-3/how-do-i-8/user-media-camera-flash-on-off-157001

    I found java script which works to turn on the camera FLASH, but always turns OFF the Construct 2

    "User Media" camera itself..

    I am hoping to find someone who can create script that can DETECT if a camera FLASHLIGHT is available

    and then turn it ON and OFF without turning OFF the Construct 2 "User Media" camera.

    My preferred solution would be if someone could ADD the FLASHLIGHT functions to the existing Construct 2

    "User Media" plugin itself, so as to simply it for myself and many other users.

    I am willing to pay for this service..

    Please contact me or reply to this posting...

  • I am wondering if the problem is caused by the fact that the example code

    I am using uses "Constants" instead of variables?

    "const photoCapabilities"

    The only way I can turn OFF the light is to RELOAD the HTML page..

  • THANK YOU dop2000,

    That works GREAT !!!

    I didn't know how to get rid of the BTN within the java script.

    QUESTION: How do I turn OFF the light once it is ON?

    I created (2) buttons on a test Construct project:

    ON Button:

    On Click = Browser RUN Java Script: "The script you helped me with"

    WORKS LIGHT ON

    OFF Button

    I tried changing the the java script to

    torch: false

    However, that did not work for some reason.

    Is there something else I am missing>

  • Hi again dop2000,

    The script creates a button, see script below..

    I am just not sure about how to control that script created button with a button

    created within a Contruct2 project.

    Can I give this script created button a "name" or UID, or something so I can generate

    a button in Construct2 to invoke this function?

     //let there be light!
    
     const btn = document.querySelector('.switch');
     btn.addEventListener('click', function(){
     track.applyConstraints({
     advanced: [{torch: true}]
    
     });
    
    
  • Hi dop2000,

    No, I have not tried that yet.

    I don't have a subscription for Construct 3, I paid for Construct 2 and would

    prefer to find a solution using software that I can actually "own" instead of "rent".

    The problem with "renting" software is that I won't be able to modify my work product

    code without endlessly paying a monthly fee.

    Thank you for helping dop2000..

    I am hoping to find a solution using my existing "paid for" Construct 2 software..

  • Hello,

    I need to be able to turn ON and OFF the camera FLASHLIGHT on the back of devices that have them.

    The Construct User Media Plug in does not include any functions for the camera FLASH..

    I found some example Java Script that WORKS !!!

    I am successfully able to control the camera FLASHLIGHT (ON and OFF) from within a web browser window.

    However, if you read my post, I cannot control the java script from a button click within my Construct project..

    I need to put a button or sprite button on my Construct project that can command the java script function..

    I would prefer a simple PLUGIN called TORCH or something which would use the java script as a source starting

    Point, and allow me to create On Clicked events.

    • Check if TORCH is PRESENT

    • TORCH ON

    • TORCH OFF

    Click here to view post..

    construct.net/en/forum/construct-3/scripting-51/construct-button-execute-157054

    Please let me know if you have a solution for my problem.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hello,

    I need to be able to turn ON and OFF the camera FLASHLIGHT on the back of devices that have them.

    The Construct User Media Plug in does not include any functions for the camera FLASH..

    I found some example Java Script that WORKS !!!

    I am successfully able to control the camera FLASHLIGHT (ON and OFF) from within a web browser window.

    However, if you read my post, I cannot control the java script from a button click within my Construct project..

    I need to put a button or sprite button on my Construct project that can command the java script function..

    I would prefer a simple PLUGIN called TORCH or something which would use the java script as a source starting

    Point, and allow me to create On Clicked events.

    • Check if TORCH is PRESENT

    • TORCH ON

    • TORCH OFF

    Click here to view post..

    construct.net/en/forum/construct-3/scripting-51/construct-button-execute-157054

    Please let me know if you have a solution for my problem.

  • Hello,

    I need to be able to turn ON and OFF the camera FLASHLIGHT on the back of devices that have them.

    The Construct User Media Plug in does not include any functions for the camera FLASH..

    I found some example Java Script that WORKS !!!

    I am successfully able to control the camera FLASHLIGHT (ON and OFF) from within a web browser window.

    However, if you read my post, I cannot control the java script from a button click within my Construct project..

    I need to put a button or sprite button on my Construct project that can command the java script function..

    I would prefer a simple PLUGIN called TORCH or something which would use the java script as a source starting

    Point, and allow me to create On Clicked events.

    • Check if TORCH is PRESENT

    • TORCH ON

    • TORCH OFF

    Click here to view post..

    construct.net/en/forum/construct-3/scripting-51/construct-button-execute-157054

    Please let me know if you have a solution for my problem.

  • I found some java script example code that WORKS GREAT for me..

    It successfully turns ON the FLASHLIGHT on the back of an Android cell phone within a Chrome browser.

    The script creates a button function, then there is HTML code that DRAWS the button itself..

    Here is the HTML code that successfully EXECUTES the java script function..

    ================================================================================

    	<html>
    		<body>
    
    <button 
     class="switch" 
     style="width: 126px; height: 64px;" > 
    </button> 
    
    		</body>
    	</html>
    

    =================================================================================

    I can successfully RUN the java script using the BROWSER PLUGIN, however...

    QUESTION: How do I program a BUTTON within Construct to EXECTUE the button function within the java script?

    Below is the java script code..

    =======================================================================================

     //Test browser support
    const SUPPORTS_MEDIA_DEVICES = 'mediaDevices' in navigator;
    
    if (SUPPORTS_MEDIA_DEVICES) {
     //Get the environment camera (usually the second one)
     navigator.mediaDevices.enumerateDevices().then(devices => {
     
     const cameras = devices.filter((device) => device.kind === 'videoinput');
    
     if (cameras.length === 0) {
     throw 'No camera found on this device.';
     }
     const camera = cameras[cameras.length - 1];
    
     // Create stream and get video track
     navigator.mediaDevices.getUserMedia({
     video: {
     deviceId: camera.deviceId,
     facingMode: ['user', 'environment'],
     height: {ideal: 1080},
     width: {ideal: 1920}
     }
     }).then(stream => {
     const track = stream.getVideoTracks()[0];
    
     //Create image capture object and get camera capabilities
     const imageCapture = new ImageCapture(track)
     const photoCapabilities = imageCapture.getPhotoCapabilities().then(() => {
    
     //todo: check if camera has a torch
    
     //let there be light!
     const btn = document.querySelector('.switch');
     btn.addEventListener('click', function(){
     track.applyConstraints({
     advanced: [{torch: true}]
     });
     });
     });
     });
     });
     
     //The light will be on as long the track exists
     
    }
    

    ====================================================================================

  • In the example JAVA script I posted here, there is a BUTTON created that turns ON the TORCH Flashlight..

    After the JAVA script, there is HTML creating a BUTTON that shows up and executes the JAVA script command

    to turn ON the TORCH Flashlight..

    I can use the BROWSER Plugin to execute the java script code..

    QUESTION: How do I get a Construct BUTTON to execute the JAVA scripted button command?

  • The following code works to turn ON the camera FLASHLIGHT, if this helps.

    ==================================================================================

    	<html>
    		<body>
    //Test browser support
    const SUPPORTS_MEDIA_DEVICES = 'mediaDevices' in navigator;
    
    if (SUPPORTS_MEDIA_DEVICES) {
     //Get the environment camera (usually the second one)
     navigator.mediaDevices.enumerateDevices().then(devices => {
     
     const cameras = devices.filter((device) => device.kind === 'videoinput');
    
     if (cameras.length === 0) {
     throw 'No camera found on this device.';
     }
     const camera = cameras[cameras.length - 1];
    
     // Create stream and get video track
     navigator.mediaDevices.getUserMedia({
     video: {
     deviceId: camera.deviceId,
     facingMode: ['user', 'environment'],
     height: {ideal: 1080},
     width: {ideal: 1920}
     }
     }).then(stream => {
     const track = stream.getVideoTracks()[0];
    
     //Create image capture object and get camera capabilities
     const imageCapture = new ImageCapture(track)
     const photoCapabilities = imageCapture.getPhotoCapabilities().then(() => {
    
     //todo: check if camera has a torch
    
     //let there be light!
     const btn = document.querySelector('.switch');
     btn.addEventListener('click', function(){
     track.applyConstraints({
     advanced: [{torch: true}]
     });
     });
     });
     });
     });
     
     //The light will be on as long the track exists
     
     
    }
    <button class="switch">On / Off</button>
    		</body>
    	</html>
    
  • The User Media Plug in needs to support Camera FLASHLIGHT, or TORCH functions.

    There are many situations where poor lighting requires a camera FLASH to take a

    decent picture.

    TORCH ON

    TORCH OFF

    TORCH FLASH

  • I found this code, that works on Android..

    ==============================================================================================

    	<html>
    		<body>
    //Test browser support
    const SUPPORTS_MEDIA_DEVICES = 'mediaDevices' in navigator;
    
    if (SUPPORTS_MEDIA_DEVICES) {
     //Get the environment camera (usually the second one)
     navigator.mediaDevices.enumerateDevices().then(devices => {
     
     const cameras = devices.filter((device) => device.kind === 'videoinput');
    
     if (cameras.length === 0) {
     throw 'No camera found on this device.';
     }
     const camera = cameras[cameras.length - 1];
    
     // Create stream and get video track
     navigator.mediaDevices.getUserMedia({
     video: {
     deviceId: camera.deviceId,
     facingMode: ['user', 'environment'],
     height: {ideal: 1080},
     width: {ideal: 1920}
     }
     }).then(stream => {
     const track = stream.getVideoTracks()[0];
    
     //Create image capture object and get camera capabilities
     const imageCapture = new ImageCapture(track)
     const photoCapabilities = imageCapture.getPhotoCapabilities().then(() => {
    
     //todo: check if camera has a torch
    
     //let there be light!
     const btn = document.querySelector('.switch');
     btn.addEventListener('click', function(){
     track.applyConstraints({
     advanced: [{torch: true}]
     });
     });
     });
     });
     });
     
     //The light will be on as long the track exists
     
     
    }
    <button class="switch">On / Off</button>
    		</body>
    	</html>
    
  • WOW !!!

    Thank you MatrixReal..

    Will this run within a Chrome web browser?

    My application needs to run within a web browser and specifically NOT INSTALL

    as an APP on the phone devices, or tablets.

  • WOW !!!

    Thank you MatrixReal..

    Will this run within a Chrome web browser?

    My application needs to run within a web browser and specifically NOT INSTALL

    as an APP on the phone devices, or tablets.