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);
}
};