Game Development Community

Spawn an object with a mouse click

by Kayrel Parcen Vandal · in TGB Platformer Kit · 10/24/2008 (6:20 am) · 2 replies

Hi, people:

Have anybody done a script spawning and object using the mouse? I trying to make some kind of painting game inside the PSK where I am using one object as a brush and it will spawn objects (inks) using the mouse. If anybody have some directions or suggestions?

thanks.

#1
10/24/2008 (3:01 pm)
What kind of object did you want to spawn? The idea is pretty simple:

function t2dSceneWindow::onMouseDragged(%this, %modifier, %worldPosition, %clicks)
{
    %myObject = new t2dStaticSprite()
    {
        SceneGraph = %this.getSceneGraph();
        ImageMap = myImageMap;
        
        Position = %worldPosition;
    };
}

Just replace the actual object with something that you want to spawn ;)
#2
10/27/2008 (11:21 am)
Hello People:

With P.O.'s help I did this little code to paint during the game. The actors respond to the paint's collision perfectly in a game without the PSK. In the PSK they ignore it. Using the PSK's ObjectManager.cs setObjectType set to SolidPlatform the PSK's actors responded, but not as the SolidPlatform's behavior does. The actor respond as slope, wall or platform, but they stay as in air. Only side movement is allowed. There is no on ground reset for jumping or running. I am sure there is more to it then just setting its type. But what and where. If someone can point the way.

Thanks.



function sceneWindow2D::onRightMouseDragged( %this, %mod, %worldPos, %mouseClicks )
{
echo("Mouse Dragging");
%this.mousePos = %worldPos;

echo(%worldPos);
%inkObject = new t2dStaticSprite()
{
SceneGraph = %this.getSceneGraph();
ImageMap = inkImageMap;
Position = %worldPos;
};
%inkObject.setSize( ".5 .5" );
%inkObject.setCollisionActive(false, true);
%inkObject.setCollisionDetection( full );
%inkObject.setCollisionCallback( true );
%inkObject.enableUpdateCallback();

// So the PSK ObjectManager.cs acknowledge the paint

%inkObject.setObjectType("SolidPlatform");
}






Thanks.