Game Development Community

How can I call my c++ object

by tianjie_gs · in iTorque 2D · 07/19/2011 (9:12 pm) · 9 replies

I see the TGB/Tutorials/The Game of Life and know how to call the scriptable object, but I want create a renderable object in c++ to render my special effect and call it in TGB use script.
I create a RenderObject extends the StaticSprite, cause I want use its texture, but seems that I can't use it directly in tgb(or I don't know how?). I find there is a fxRenderObject,much similar as my RenderObject, so can anyone tell me how to call the fxRenderObject? use datablock?or I need update my iTGB to 1.5 to use it just through drag motion.

#1
07/20/2011 (6:21 am)
@tianjie_gs - I removed your duplicate threads, since you are working with iTorque 2D. I'm not exactly following what you are attempting. Please link to the tutorial you are following. Also, can you answer the following questions so we can get to an answer:

1. What does your class declaration look like?
2. Did you remember to declare and implement the con object?
#2
07/21/2011 (6:39 pm)
this is my class head file

#ifndef _MYRIBBON_H_
#define _MYRIBBON_H_

#ifndef _T2DSTATICSPRITE_H_
#include "t2dStaticSprite.h"
#endif

#ifndef _T2DIMAGEMAPDATABLOCK_H_
#include "t2dImageMapDatablock.h"
#endif

#include "dgl/dgl.h"

#ifndef _TVECTOR_H_
#include "core/tVector.h"
#endif

///-----------------------------------------------------------------------------
/// Static Object 2D.
///-----------------------------------------------------------------------------

class MyRibbon : public t2dStaticSprite
{
    typedef t2dStaticSprite          Parent;

public:
    MyRibbon();
    virtual ~MyRibbon();
    
    static void initPersistFields();
    
    virtual bool onAdd();
    virtual void onRemove();
    virtual void renderObject( const RectF& viewPort, const RectF& viewIntersection );
    
    virtual void copyTo(SimObject* object);
    
        /// Declare Serialise Object.
    DECLARE_T2D_SERIALISE( MyRibbon );
    
    DECLARE_T2D_LOADSAVE_METHOD( MyRibbon, 3 );
    /// Declare Console Object.
    DECLARE_CONOBJECT( MyRibbon );
    
    void integrateObject( const F32 sceneTime, const F32 elapsedTime, CDebugStats* pDebugStats );

};

#endif

I override the renderObject and integrateObject function, so how can i create it in tgb?
because it extends from StaticSprite,in tgb I just can create staticSprite,I want convert StaticSprite to my class.


#3
07/21/2011 (7:34 pm)
How do you load that from script? Anything like this?

%ribbon = new MyRibbon()
{
}

If so, what errors do you get?
#4
07/25/2011 (6:39 pm)
thanks for your reply, I do things like this:

I create a StaticSprite named ribbon and link to a class named ribbonClass, I want dynamic convert the ribbonClass to MyRibbon.

Now , I do things like this below:
new t2dImageMapDatablock(ribbonImageMap) {
      imageName = "~/data/images/ribbon.png";
      .....
      .....
};

$ribbon = new MyRibbon() 
{
   imageMap = "ribbonImageMap";
   position = "12.5693 35.5857 59.5747";
   rotation = "1 0 0 0";
   scale = "1 1 1";
};

but I can't edit $ribbon in iTGB....
#5
07/26/2011 (6:37 am)
What does your console log report? Any warnings or errors?
#6
07/27/2011 (10:42 pm)
$ribbon = new MyRibbon() 
{
    imageMap = "ribbon";  
    frame = "0";
    mUseSourceRect = "0";
    sourceRect = "0 0 0 0";
    canSaveDynamicFields = "1";
    Position = "-137.951 -46.000";
    size = "128.000 128.000";
    CollisionMaxIterations = "3";
    mountID = "4";
};

if(isObject($ribbon))
{
   // I forget to attach my ribbon to current scenegraph
    %scenegraph = /*how to get current scenegraph or camera*/

    %scenegraph.addToScene($ribbon);
    echo("add My Ribbon to Scene");
}

hi, it's all my fault that I forget add my ribbon to scenegraph , and there seems no error output, so can you tell me how to get current scenegraph or camera , I can add ribbon to the scene.
#7
07/28/2011 (6:40 am)
@tianjie_gs - You can get the scenegraph using the following code:

%sceneGraph = sceneWindow2D.getSceneGraph();
#8
07/28/2011 (10:04 pm)
Thanks michael, you are so cool
#9
07/28/2011 (10:24 pm)
You're welcome! Glad I could help =)