How do I get some parameters of instance through JS.

0 favourites
  • 2 posts
  • And how do I get the parameters of a instance's effect.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Some example code, set globalThis.globalRuntime = runtime in startup scripts.

    Also see:

    var topLtX = localVars.topLtX
    var topLtY = localVars.topLtY
    var topRtX = localVars.topRtX
    var topRtY = localVars.topRtY
    var botLtX = localVars.botLtX
    var botLtY = localVars.botLtY
    var botRtX = localVars.botRtX
    var botRtY = localVars.botRtY
    var effectIndex = localVars.effectIndex
    // Get instance details
    var inst = globalThis.globalRuntime.GetInstanceByUID(localVars.uid)
    var wi = inst.GetWorldInfo()
    // Find bounding box
    var minX = Math.min(topLtX, topRtX, botLtX, botRtX)
    var minY = Math.min(topLtY, topRtY, botLtY, botRtY)
    var maxX = Math.max(topLtX, topRtX, botLtX, botRtX)
    var maxY = Math.max(topLtY, topRtY, botLtY, botRtY)
    // Calc bonding box
    var width = maxX - minX
    var height = maxY - minY
    // Set bounding box
    // Calc normalized relative range (0-1) for texture X,Y coords from pixel locations
    topLtX = (topLtX-minX)/width
    topLtY = (topLtY-minY)/height
    topRtX = (topRtX-minX)/width
    topRtY = (topRtY-minY)/height
    botLtX = (botLtX-minX)/width
    botLtY = (botLtY-minY)/height
    botRtX = (botRtX-minX)/width
    botRtY = (botRtY-minY)/height
    // Set effect parameters (takes 5%+ CPU  2000 objects)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,0,topLtX)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,1,topLtY)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,2,topRtX)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,3,topRtY)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,4,botLtX)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,5,botLtY)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,6,botRtX)
    inst._sdkInst.CallAction(C3.Plugins.Sprite.Acts.SetEffectParam, effectName,7,botRtY
    // (take 1%+ CPU  2000 objects to find index by effectName), instead pass in effectIndex to function
    // var effectIndex = inst.GetObjectClass().GetEffectList().GetEffectTypeByName(effectName).GetIndex()
    // Set effect parameters by ref (faster than CallAction)
    var effectParam = wi.GetInstanceEffectList().GetEffectParametersForIndex(effectIndex)
    effectParam[0]= topLtX
    effectParam[1]= topLtY
    effectParam[2]= topRtX
    effectParam[3]= topRtY
    effectParam[4]= botLtX
    effectParam[5]= botLtY
    effectParam[6]= botRtX
    effectParam[7]= botRtY
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)