Game Development Community

How to move a sprite?

by Daryll Todd · in Torque Game Engine · 09/16/2008 (12:40 pm) · 2 replies

Hi again,

I feel like I should know the answer to this or have rad it somewhere..sorry in advance if thats the case..

How can I set the x or y position of a sprite that was created in one cs file using the function of another?

Does that make sense? This is what I have (with anything not relevant removed)


***player.cs***

function PlayerShip::playerHealth(%this)
{

%this.playerHealth = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = PlayerHealth;

player = %this;
};

%this.playerHealth.create();
}



***playerHealth.cs***

function PlayerHealth::create(%this)
{
// Pick the image and set its size
%this.setImageMap(healthBarInnerImageMap);
%this.setSize(30.664, 6.739);

//Set Position
%this.setPositionX(-84);
%this.setPositionY(71);
%this.setLayer(1);

}

That works fine and the initial sprite is created, however I then want to be able to adjust the x & y value of that sprite from a 3rd .cs file - can that be done?

I know this is probably not the best way to go about this but id like to know for future reference anyway.

#1
09/16/2008 (1:19 pm)
Aha a little more digging and i think ive sussed it - just had to declare $pHealth and call the function in that :)

Sorry - I posted in haste ;)
#2
09/17/2008 (3:44 pm)
This is also the TGE public forum, one of the TGB forums would be a better bet.