Results 1 to 11 of 11

Thread: Adding a Custom Component to Proton SDK

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Squire
    Join Date
    Jan 2012
    Posts
    10

    Default Adding a Custom Component to Proton SDK

    Hi!
    I've to add a custom component to the SDK. The component has to move any entity (like an overlay entity or button entity)
    from the top of the screen to bottom and from bottom top(i.e wrap over) for ever. What are the steps to add a custom component?
    How to move an entity from top to bottom and bottom to top forever?

    I'm doing some thing like this inside the OnAdd() function my entity:

    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));

    But it didn't do anything. Inserting the above code inside a infinite loop like for( ;; ) is also not working.
    What to do?
    Last edited by rtr_18; 01-13-2012 at 09:22 AM.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Squire
    Join Date
    Jan 2012
    Posts
    10

    Default

    Quote Originally Posted by Seth View Post
    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    I need a component any how. I used the following code:

    if((pEnt->GetVar("pos2d")->GetVector2().y < GetScreenSizeY()) && (pEnt->GetVar("pos2d")->GetVector2().y >= 0))
    {
    //m_bDirForward = true;
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    }
    else
    if((pEnt->GetVar("pos2d")->GetVector2().y > 0) && (pEnt->GetVar("pos2d")->GetVector2().y == GetScreenSizeY()))
    {
    //m_bDirForward = false;
    GetMessageManager()->SetEntityVariable(pEnt, 6000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    }
    But the entity is moved out of the window(my requirement is: it has to be moved to the bottom first and then to the top once it reaches the bottom).
    This has to be done repeatedly for the entity.

  4. #4
    Squire
    Join Date
    Jan 2012
    Posts
    10

    Default Adding Custom Component to Proton SDK

    Quote Originally Posted by Seth View Post
    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    Hi!
    I've used the following code:

    if((pEnt->GetVar("pos2d")->GetVector2().y < GetScreenSizeY()) && (pEnt->GetVar("pos2d")->GetVector2().y >= 0))
    {
    //m_bDirForward = true;
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    }
    else
    if((pEnt->GetVar("pos2d")->GetVector2().y > 0) && (pEnt->GetVar("pos2d")->GetVector2().y == GetScreenSizeY()))
    {
    //m_bDirForward = false;
    GetMessageManager()->SetEntityVariable(pEnt, 6000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    }

    But it waits for 3 seconds and moved the entity out of the screen. What modifications has to be done to move it to the bottom first and then to top then to bottom continuously?

  5. #5
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Ok, first, I would wire up your OnUpdate in your component so it gets called every frame. Then do your movement in there, and don't bother with MessageManager.

    Untested code:

    Code:
    //Some where in your OnAdd you need something like this so it will get called:
    
    GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&MyComponent::OnUpdate, this, _1));
    
    
    void MyComponent::OnUpdate(VariantList *pVList)
    {
         LogMsg("If you don't see this message every frame, something is wrong!");
    
        float speed = 3;
        m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    
       if (m_pPos2d->y > GetScreenSizeYf())
       {
      //move it back to the top of the screen
       m_pPos2d->y = 0;
       }
    
    }
    Something like that. Note that this assumes this entity has an OverlayRenderComponent added to its entity as a sibling to this component, otherwise moving the position like that won't matter, as nothing would be rendering.
    Seth A. Robinson
    Robinson Technologies

  6. #6
    Squire
    Join Date
    Jan 2012
    Posts
    10

    Default

    Quote Originally Posted by Seth View Post
    Ok, first, I would wire up your OnUpdate in your component so it gets called every frame. Then do your movement in there, and don't bother with MessageManager.

    Untested code:

    Code:
    //Some where in your OnAdd you need something like this so it will get called:
    
    GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&MyComponent::OnUpdate, this, _1));
    
    
    void MyComponent::OnUpdate(VariantList *pVList)
    {
         LogMsg("If you don't see this message every frame, something is wrong!");
    
        float speed = 3;
        m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    
       if (m_pPos2d->y > GetScreenSizeYf())
       {
      //move it back to the top of the screen
       m_pPos2d->y = 0;
       }
    
    }
    Something like that. Note that this assumes this entity has an OverlayRenderComponent added to its entity as a sibling to this component, otherwise moving the position like that won't matter, as nothing would be rendering.

    Only the top to bottom movement is working now also. Here's the code modified by me.
    Code:
       
        float speed = 0.3;
        
    	if((m_pPos2d->y >= 0) && (m_pPos2d->y <= GetScreenSizeYf()))
    	{
    		m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    	}
    	if ((m_pPos2d->y >= GetScreenSizeYf()) && (m_pPos2d->y < 0))
    	{
    		//move it back to the top of the screen
    		m_pPos2d->y = 0;//speed*GetBaseApp()->GetGameDeltaTick();
    	}

  7. #7
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Your code:

    Code:
    if ((m_pPos2d->y >= GetScreenSizeYf()) && (m_pPos2d->y < 0))
    	{
    		//move it back to the top of the screen
    		m_pPos2d->y = 0;//speed*GetBaseApp()->GetGameDeltaTick();
    	}
    So, you want to move your y to 0 if y is > GetScreenSizeYf() *AND* if y is less than 0?

    It's impossible for both of things to be true at the same time. Why did you add the m_pPos2d->y < 0 part?
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. Adding a full 360 screen rotation
    By Roadkill in forum Tanked
    Replies: 4
    Last Post: 11-28-2011, 02:03 AM
  2. Adding clanlib dependencies to a project
    By Topi in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 10-21-2011, 08:28 PM
  3. adding FPS Key and mouse controls to RT3DApp
    By BigBMan in forum Proton SDK
    Replies: 2
    Last Post: 11-11-2010, 06:49 AM
  4. New example in ClanLib 2.0: Custom GUI Component
    By sphair in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-19-2009, 02:08 PM
  5. Adding Di-Mart Guns
    By in forum Funeral Quest
    Replies: 5
    Last Post: 03-28-2005, 09:18 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •