It looks like you're new here. If you want to get involved, click one of these buttons!
orxOBJECT * createImageObject (char * filename, float pos_x,
float pos_y, float scale_x, float scale_y)
{
orxOBJECT * obj = orxObject_Create ();
orxFRAME * frame = orxFrame_Create (orxFRAME_KU32_FLAG_NONE);
orxObject_LinkStructure (obj, (orxSTRUCTURE*) frame);
orxTEXTURE * tex = orxTexture_CreateFromFile (filename, orxTRUE);
orxFLOAT image_x;
orxFLOAT image_y;
orxTexture_GetSize (tex, &image_x, &image_y);
orxGRAPHIC * gfx = orxGraphic_Create ();
orxGraphic_SetData (gfx, (orxSTRUCTURE*) tex);
orxObject_LinkStructure (obj, (orxSTRUCTURE*)gfx);
orxVECTOR v;
v.fX = image_x;
v.fY = image_y;
v.fZ = 1.0;
orxObject_SetSize (obj, &v);
v.fX = pos_x;
v.fY = pos_y;
v.fZ = 0.0;
orxObject_SetPosition (obj, &v);
v.fX = scale_x;
v.fY = scale_y;
v.fZ = 1.0;
orxObject_SetScale (obj, &v);
return obj;
}
Comments
Don't hesitate to ask questions either here or on the chat (https://gitter.im/orx/orx) if you find yourself stuck or struggling too much.
In your example, you'll be in charge of doing the cleanup yourself: you're the owner of what you directly created, in this case the orxGRAPHIC, the orxTEXTURE and the orxFRAME.
If you still want a dynamic approach but without having to trouble yourself with the bookkeeping, you can modify the config's content on the fly. Here's a quick example (I've written it directly on the forum so it might not fully work/compile):
Of course both position and scale could also be passed via config, but in that case there's no ulterior bookkeeping to be made so I left them as is. You can of course modify any other relevant property or inherit from other sections as you see fit.
I guess that's the more standard way of creating objects dynamically in Orx.
My pleasure. Your approach definitely works so don't hesitate to use it if you prefer it. I'm just a bit lazy and I'd rather have the engine doing the cleanup instead of doing it myself, that's why I choose the second option.
This might make a good small tutorial if you don't mind me pinching the code for the wiki.
I think a tutorial about manually creating objects and cleaning them up would be a good idea. Sure, feel free to reuse any of this code.
If you need more advices, have any questions or just want to chat, don't hesitate to use the chat as well: https://gitter.im/orx/orx