mOOnpunk's Forum Posts

  • Ashley

    I'm getting an error

    "Failed to load all engine scripts in worker: TypeError: Class extends value undefined is not a constructor or null

    at type.js:3:69"

    Used C3.SDKPluginBase for plugin.js, C3.SDKWorldInstanceBase for instance.js, and C3.SDKObjectTypeBase for type.js.

    All three classes are undefined, causing the same error in each file.

    The plugin works fine in the editor (edit-time scripts use SDK.IPluginBase, etc.).

    The plugin defines a custom collision polygon via getCollisionPoly and uses runtime.testOverlapInstances for the IsOverlapping condition, which should work once the runtime loads.

  • There is also this plugin.

    construct.net/en/make-games/addons/538/rexsequencematcher-c3runtime

    Not sure if its sdk 2 though.

  • R0J0hound i couldn't get my files to work, so i've extended yours, using polyK.js to compute the earclipping.

    Hope you dont mind.

    I just need to add the actions and expressions then i'll release it for the community.

  • I'm sorry. I misread your reply.

  • I cant get Draw() to work no matter what i do.

    I modified the example and only _draw will call, even though my files are set up and configured for SDK V2.

    const C3 = globalThis.C3;

    C3.Plugins.MyCompany_PolygonRenderer.Instance = class PolygonRendererInstance extends globalThis.ISDKWorldInstanceBase {

    constructor() {

    super();

    console.log("[PolygonRenderer] Constructor executed for instance");

    }

    OnAddedToLayout() {

    console.log("[PolygonRenderer] OnAddedToLayout executed for instance");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Position after OnAddedToLayout: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}`);

    }

    OnCreated() {

    console.log("[PolygonRenderer] OnCreated executed for instance");

    this._InitializeInstance();

    }

    OnCreate() {

    console.log("[PolygonRenderer] OnCreate executed for instance (testing SDK v1 compatibility)");

    this._InitializeInstance();

    }

    _InitializeInstance() {

    const worldInfo = this._inst.GetWorldInfo();

    // Force position to a visible area for debugging

    worldInfo.SetX(100);

    worldInfo.SetY(100);

    worldInfo.SetWidth(50);

    worldInfo.SetHeight(50);

    worldInfo.SetBboxChanged();

    console.log(`[PolygonRenderer] Instance position after initialization: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}, width:${worldInfo.GetWidth()}, height:${worldInfo.GetHeight()}`);

    const layer = this.layer;

    if (layer) {

    console.log(`[PolygonRenderer] Layer properties: visible=${layer.isVisible}, opacity=${layer.opacity}, scale=${layer.scale}, parallaxX=${layer.parallaxX}, parallaxY=${layer.parallaxY}`);

    // Force layer visibility for debugging

    layer.isVisible = true;

    layer.opacity = 1;

    } else {

    console.warn("[PolygonRenderer] No layer information available for this instance");

    }

    // Force instance visibility

    this._inst.SetVisible(true);

    console.log(`[PolygonRenderer] Instance visibility forced: visible=${this._inst.isVisible}`);

    // Log runtime and layout information

    const runtime = this._runtime;

    if (runtime) {

    console.log(`[PolygonRenderer] Runtime layout: width=${runtime.GetMainRunningLayout().GetWidth()}, height:${runtime.GetMainRunningLayout().GetHeight()}`);

    const allInstances = runtime.GetMainRunningLayout().GetAllInstances();

    console.log(`[PolygonRenderer] Total instances in layout: ${allInstances.length}`);

    let found = false;

    for (const inst of allInstances) {

    if (inst === this._inst) {

    found = true;

    console.log(`[PolygonRenderer] This instance found in layout: UID=${inst.GetUID()}`);

    }

    }

    if (!found) {

    console.warn("[PolygonRenderer] This instance NOT found in layout instances!");

    }

    }

    }

    OnLayoutStart() {

    console.log("[PolygonRenderer] OnLayoutStart executed for instance");

    }

    OnLayoutEnd() {

    console.log("[PolygonRenderer] OnLayoutEnd executed for instance");

    }

    Tick() {

    console.log("[PolygonRenderer] Tick executed for instance");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Position in Tick: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}`);

    // Force position each frame to ensure it stays at x=100, y=100

    if (worldInfo.GetX() !== 100 || worldInfo.GetY() !== 100) {

    console.warn("[PolygonRenderer] Position was overridden, forcing back to x=100, y=100");

    worldInfo.SetX(100);

    worldInfo.SetY(100);

    worldInfo.SetBboxChanged();

    }

    }

    getBoundingQuad() {

    if (!this._inst) {

    console.warn("[PolygonRenderer] getBoundingQuad called before instance is fully initialized");

    return new C3.Quad();

    }

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Getting bounding quad for instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height:${worldInfo.GetHeight()}`);

    const quad = super.getBoundingQuad();

    console.log(`[PolygonRenderer] Default bounding quad: minX=${worldInfo.GetX()}, minY=${worldInfo.GetY()}, width=${worldInfo.GetWidth()}, height=${worldInfo.GetHeight()}`);

    return quad;

    }

    Draw(renderer) {

    if (!this._inst) {

    console.warn("[PolygonRenderer] Draw called before instance is fully initialized");

    return;

    }

    console.log("[PolygonRenderer] *** DRAW METHOD EXECUTED ***");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Drawing instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height: ${worldInfo.GetHeight()}`);

    // Set up renderer state

    renderer.setBlendMode("normal"); // Set normal alpha blending

    renderer.setColorFillMode(); // Set fill mode to color fill

    renderer.setColorRgba(1, 0, 0, 1); // Red, fully opaque

    // Draw a simple 50x50 red square at the instance's position

    renderer.rect(worldInfo.GetX(), worldInfo.GetY(), worldInfo.GetX() + 50, worldInfo.GetY() + 50);

    }

    _draw(renderer) {

    // Test if runtime expects SDK v1 method name

    if (!this._inst) {

    console.warn("[PolygonRenderer] _draw called before instance is fully initialized");

    return;

    }

    console.log("[PolygonRenderer] *** _draw METHOD EXECUTED ***");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] _draw instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height: ${worldInfo.GetHeight()}`);

    // Set up renderer state

    renderer.setBlendMode("normal"); // Set normal alpha blending

    renderer.setColorFillMode(); // Set fill mode to color fill

    renderer.setColorRgba(1, 0, 0, 1); // Red, fully opaque

    // Draw a simple 50x50 red square at the instance's position

    renderer.rect(worldInfo.GetX(), worldInfo.GetY(), worldInfo.GetX() + 50, worldInfo.GetY() + 50);

    }

    };

  • Then why does the official sdk V2 drawing example runtime instance.js use _draw?

    const C3 = globalThis.C3;

    const tempQuad = new C3.Quad();

    C3.Plugins.MyCompany_DrawingPlugin.Instance = class DrawingInstance extends globalThis.ISDKWorldInstanceBase

    {

    constructor()

    {

    super();

    this._testProperty = 0;

    const properties = this._getInitProperties();

    if (properties)

    {

    this._testProperty = properties[0];

    }

    }

    _release()

    {

    super._release();

    }

    _draw(renderer)

    {

    const imageInfo = this.objectType.getImageInfo();

    const texture = imageInfo.getTexture(renderer);

    if (!texture)

    return; // dynamic texture load which hasn't completed yet; can't draw anything

    let quad = this.getBoundingQuad();

    const rcTex = imageInfo.getTexRect();

    renderer.setTexture(texture);

    if (this.runtime.isPixelRoundingEnabled)

    {

    const ox = Math.round(this.x) - this.x;

    const oy = Math.round(this.y) - this.y;

    if (ox !== 0 && oy !== 0)

    {

    quad = new DOMQuad(new DOMPoint(quad.p1.x + ox, quad.p1.y + oy),

    new DOMPoint(quad.p2.x + ox, quad.p2.y + oy),

    new DOMPoint(quad.p3.x + ox, quad.p3.y + oy),

    new DOMPoint(quad.p4.x + ox, quad.p4.y + oy));

    }

    }

    renderer.quad3(quad, rcTex);

    }

    _saveToJson()

    {

    return {

    // data to be saved for savegames

    };

    }

    _loadFromJson(o)

    {

    // load state for savegames

    }

    _setTestProperty(n)

    {

    this._testProperty = n;

    }

    _getTestProperty()

    {

    return this._testProperty;

    }

    };

  • I see.

    Ashley

    Can you shed some light on things?

    is _draw V2 or V1?

    Thanks.

  • Hi.

    You seem to be using _draw for rendering which is SDK v1 i think?

    Half my problem is trying to get Draw() SDK v2 to work.

    I'll keep looking.

  • That very much for your help.

    My experience mirrors your own. I made a polygon plugin which uses ear clipping and can render concave shapes, it all works fine in the editor, but trying to get it to work at runtime since it uses different methods is annoying.

    The SDK is unhelpful. There are hardly any example files. We don't have access to built in plugins to study them. I tried looking at some 3rd party ones in the repository, but there aren't any graphical ones and most are V1.

    I will take a look at your example and figure out what i'm doing wrong.

    Thanks again.

  • Is there a simple graphical example i can study some where?

    The SDK is very confusing. A lot of it says SDK V1 only, you click a link to SDK 2 and it sends you back to the same SDK pages with warnings at the top.

  • Thanks.

    If i use my method i can get the object to render but the bounding box doesn't update.

    If i use your method, the bounding box works but the i cant get the object to render at runtime.

  • How do i get the bounding box of my object to update when the window is resized?

    Construct 3 updates this.x and this.y when the layout resizes but getBoundingQuad doesnt appear to be automatically called. I'm using layer.layerToCssPx.

    It updates when i use SetPosition.

    Don't now if any of this is correct as i'm new to this.

    Thanks.

  • You do not have permission to view this post

  • Thanks ASHLEY.

    One of the issues with drawing canvas is that if i space the stars out more, which i need to, then that increases the memory used considerably. That's why i wanted to use a polygon, or mesh, so i can use a small sprite and stretch it. It only needs to be white so i can colour it at runtime and use blends for textures.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Would a polygon plugin be possible in c3, which uses ear clipping?

    I don't have experience making plugins, but do we have access to polygons in the sdk from meshes?