Referencing Name field in script
by KH · in iTorque 2D · 12/13/2011 (6:30 pm) · 2 replies
Hi people
I have a feeling I'm missing a core understanding with this question but is there a way to name the object in script like you can in the builder?
Essentially, I'm trying to reproduce the code below (from the documentation) without using the builder to use Per-Object Touch input:
function Cloud::onTouchDown(%this, %touchID, %worldPos)
{
echo("Finger " @ %touchID @ " touched the Cloud at " @ %worldPos);
// If we are already dragging, do nothing
// Otherwise, assign this finger to the cloud's touch ID
if(Cloud.touchID $= "")
{
Cloud.touchID = %touchID;
}
}
(In this case, Cloud is referencing the Name of the object in the builder instead of Class)
The following is the code is what I have so far (which does not work):
function createFish(%scenegraph)
{
%angelfish1animation = new t2dAnimatedSprite()
{
animationName = "angelfish1sheetAnimation";
internalName = "playerFish";
config = "angelFishDataBlock";
useMouseEvents = "1";
};
%angelfish1animation.addToScene(%scenegraph);
}
function playerFish::onTouchDown(%this, %touchID, %worldPos) {
if (playerFish.touchID $= "") {
playerFish.touchID = %touchID;
playerFish.moveTo("0 0", "50", true, false, false, 0.5);
}
}
Thanks for any help I get!
I have a feeling I'm missing a core understanding with this question but is there a way to name the object in script like you can in the builder?
Essentially, I'm trying to reproduce the code below (from the documentation) without using the builder to use Per-Object Touch input:
function Cloud::onTouchDown(%this, %touchID, %worldPos)
{
echo("Finger " @ %touchID @ " touched the Cloud at " @ %worldPos);
// If we are already dragging, do nothing
// Otherwise, assign this finger to the cloud's touch ID
if(Cloud.touchID $= "")
{
Cloud.touchID = %touchID;
}
}
(In this case, Cloud is referencing the Name of the object in the builder instead of Class)
The following is the code is what I have so far (which does not work):
function createFish(%scenegraph)
{
%angelfish1animation = new t2dAnimatedSprite()
{
animationName = "angelfish1sheetAnimation";
internalName = "playerFish";
config = "angelFishDataBlock";
useMouseEvents = "1";
};
%angelfish1animation.addToScene(%scenegraph);
}
function playerFish::onTouchDown(%this, %touchID, %worldPos) {
if (playerFish.touchID $= "") {
playerFish.touchID = %touchID;
playerFish.moveTo("0 0", "50", true, false, false, 0.5);
}
}
Thanks for any help I get!
#2
Thanks for that!
I got it to work by adding in the 'playerFish' name after t2dAnimatedSprite as you instructed.
I'll keep in mind how to format code and put in better commenting the next time I ask a question as you have suggested.
12/14/2011 (11:27 am)
Hi RayThanks for that!
I got it to work by adding in the 'playerFish' name after t2dAnimatedSprite as you instructed.
I'll keep in mind how to format code and put in better commenting the next time I ask a question as you have suggested.
Ray Delia
SK Studios
function createFish(%scenegraph) { %angelfish1animation = new t2dAnimatedSprite(playerFish){ //add your name here, but //if you call this function more than once, you will have two fish with the same name animationName = "angelfish1sheetAnimation"; internalName = "playerFish"; config = "angelFishDataBlock"; //do you have a datablock configured for this somewhere else? useMouseEvents = "1"; }; %angelfish1animation.addToScene(%scenegraph); } function playerFish::onTouchDown(%this, %touchID, %worldPos) { if (playerFish.touchID $= "") { playerFish.touchID = %touchID; playerFish.moveTo("0 0", "50", true, false, false, 0.5); } }You may want to format your code like this, so that it is easier to work with.
I don't see where you are creating your fish, but i would guess you have a line in game.cs that is like:
-Ray