Playing Animations with key presses
by Tavershima Shande · in Torque Game Builder · 07/14/2006 (2:45 pm) · 7 replies
Could any one help me to get my player (mannequin from the platform tutorial) to play an animation when I hit a key. Right now I can only move around the player while he plays the same looping animation. I would like for the run cycle animation to play when I hit left or right and the jump animation to play when I hit the "up" key.
All the code snippetts in the platform tutorial are great but they're not very clear on where they need to be placed. What do i need to have in my gamescripts folder ? a player cs. a datablocks.cs, a game.cs.
I've searched the forums and doucumentation and still can't find answers... All I want to do is properly have a controlable player on screen that plays the correct animation in association with the keys pressed. Can anyone help? It would greatly be appreciated. I'll even trade art for code help :)
-Tav
www.tavshande.com
All the code snippetts in the platform tutorial are great but they're not very clear on where they need to be placed. What do i need to have in my gamescripts folder ? a player cs. a datablocks.cs, a game.cs.
I've searched the forums and doucumentation and still can't find answers... All I want to do is properly have a controlable player on screen that plays the correct animation in association with the keys pressed. Can anyone help? It would greatly be appreciated. I'll even trade art for code help :)
-Tav
www.tavshande.com
#2
I've been working on trying to get my platformer player moving properly for a while now so I used the fish tutorial movement code for my player.cs mixed in with the code snippets from the platformer tutorial. It's a pretty crappy feeling when you hit the play button in the editor and your player doesn't respond to any key presses. so try this for your player.cs
function player::onLevelLoaded(%this, %scenegraph)
{
// Define the player global variable
$player = %this;
// Get the value of gravity from the Level Builder
%force = $player.getConstantForce();
$gravity = getWord(%force, 1);
// Player movement functions
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
}
function player::updateMovement(%this)
{
if(%this.moveLeft)
{
$player.setFlipX(true);
$player.setLinearVelocityX( -$player.hSpeed );
}
if(%this.moveRight)
{
$player.setFlipX(false);
$player.setLinearVelocityX( $player.hSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
}
function playerLeft()
{
$player.moveLeft = true;
$player.updateMovement();
}
function playerRight()
{
$player.moveRight = true;
$player.updateMovement();
}
function playerJump()
{
$player.setImpulseForce("0 -30");
//$player.setLinearVelocityY(-10 * $player.jumpHeight);
}
function playerLeftStop()
{
$player.moveLeft = false;
$player.updateMovement();
}
function playerRightStop()
{
$player.moveRight = false;
$player.updateMovement();
}
function updatePlayer()
{
%move = $moveRight - $moveLeft;
if ($runSurface > 0)
{
if ($jump)
playerJump();
}
else if ($runSurface < 0)
{
%speed = $player.getLinearVelocityX();
if (%move)
{
if (((%speed * %move) <= 0) || (mAbs(%speed) < $player.airSpeed))
$player.setLinearVelocityX(%move * $player.airSpeed);
}
}
}
//-----------------------------------------------------------------------------
// Generate Player.
//-----------------------------------------------------------------------------
function createPlayer()
{
$player = new t2dStaticSprite()
{
scenegraph = t2dscene;
};
$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($playerLayer);
$player.setGraphGroup($playerGroup);
$player.setCollisionMasks(BIT($platformGroup), BIT($platformLayer));
$player.setCollisionPolyPrimitive(8);
$player.setMaxLinearVelocity(250);
$player.runSpeed = 40;
$player.airSpeed = 16;
$player.jumpHeight = 10;
$player.maxRunSurfaceAngle = 35;
}
function resetPlayer(%pos)
{
$player.setPosition(%pos);
$player.setConstantForce(0 SPC $gravity, true);
}
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef,
%dstRef, %time, %normal, %contactCount, %contacts)
{
switch (%srcObj.getGraphGroup())
{
case $playerGroup:
switch (%dstObj.getGraphGroup())
{
case $platformGroup:
collidePlayerPlatform(%normal);
}
}
}
function collidePlayerPlatform(%normal)
{
%move = $moveRight - $moveLeft;
$runSurface = isRunSurface(%normal, $player.maxRunSurfaceAngle);
if ($runSurface > 0)
{
$player.setLinearVelocityX(%move * $player.runSpeed);
}
}
//----------------------------------------------------------------------------------------------
Don't forget to select your player in the Level Builder and then hit the Edit tab. After that go to your dynamic fields roll out menu and enter vSpeed (field Name) and 15 for (field value). Then add hSpeed for the field name and 30 for the value. This will give your player horizontal and vertical speed.
try it out and let me know if you can get your mannequin moving. BTW i named my mannequin image "player.png"
Others feel free to correct any erroneous or un-needed code above.
-Tav
www.tavshande.com
07/15/2006 (1:12 pm)
Hey Corey, I've been working on trying to get my platformer player moving properly for a while now so I used the fish tutorial movement code for my player.cs mixed in with the code snippets from the platformer tutorial. It's a pretty crappy feeling when you hit the play button in the editor and your player doesn't respond to any key presses. so try this for your player.cs
function player::onLevelLoaded(%this, %scenegraph)
{
// Define the player global variable
$player = %this;
// Get the value of gravity from the Level Builder
%force = $player.getConstantForce();
$gravity = getWord(%force, 1);
// Player movement functions
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
}
function player::updateMovement(%this)
{
if(%this.moveLeft)
{
$player.setFlipX(true);
$player.setLinearVelocityX( -$player.hSpeed );
}
if(%this.moveRight)
{
$player.setFlipX(false);
$player.setLinearVelocityX( $player.hSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
}
function playerLeft()
{
$player.moveLeft = true;
$player.updateMovement();
}
function playerRight()
{
$player.moveRight = true;
$player.updateMovement();
}
function playerJump()
{
$player.setImpulseForce("0 -30");
//$player.setLinearVelocityY(-10 * $player.jumpHeight);
}
function playerLeftStop()
{
$player.moveLeft = false;
$player.updateMovement();
}
function playerRightStop()
{
$player.moveRight = false;
$player.updateMovement();
}
function updatePlayer()
{
%move = $moveRight - $moveLeft;
if ($runSurface > 0)
{
if ($jump)
playerJump();
}
else if ($runSurface < 0)
{
%speed = $player.getLinearVelocityX();
if (%move)
{
if (((%speed * %move) <= 0) || (mAbs(%speed) < $player.airSpeed))
$player.setLinearVelocityX(%move * $player.airSpeed);
}
}
}
//-----------------------------------------------------------------------------
// Generate Player.
//-----------------------------------------------------------------------------
function createPlayer()
{
$player = new t2dStaticSprite()
{
scenegraph = t2dscene;
};
$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($playerLayer);
$player.setGraphGroup($playerGroup);
$player.setCollisionMasks(BIT($platformGroup), BIT($platformLayer));
$player.setCollisionPolyPrimitive(8);
$player.setMaxLinearVelocity(250);
$player.runSpeed = 40;
$player.airSpeed = 16;
$player.jumpHeight = 10;
$player.maxRunSurfaceAngle = 35;
}
function resetPlayer(%pos)
{
$player.setPosition(%pos);
$player.setConstantForce(0 SPC $gravity, true);
}
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef,
%dstRef, %time, %normal, %contactCount, %contacts)
{
switch (%srcObj.getGraphGroup())
{
case $playerGroup:
switch (%dstObj.getGraphGroup())
{
case $platformGroup:
collidePlayerPlatform(%normal);
}
}
}
function collidePlayerPlatform(%normal)
{
%move = $moveRight - $moveLeft;
$runSurface = isRunSurface(%normal, $player.maxRunSurfaceAngle);
if ($runSurface > 0)
{
$player.setLinearVelocityX(%move * $player.runSpeed);
}
}
//----------------------------------------------------------------------------------------------
Don't forget to select your player in the Level Builder and then hit the Edit tab. After that go to your dynamic fields roll out menu and enter vSpeed (field Name) and 15 for (field value). Then add hSpeed for the field name and 30 for the value. This will give your player horizontal and vertical speed.
try it out and let me know if you can get your mannequin moving. BTW i named my mannequin image "player.png"
Others feel free to correct any erroneous or un-needed code above.
-Tav
www.tavshande.com
#3
Thanks for the help.
07/15/2006 (6:23 pm)
Thanks Tavershima, I'll give that a try. I was thinking about doing something similar to that already, I was just a little annoyed that I'd followed the platformer tutorial to the letter and still couldn't get my player to move. Thanks for the help.
#4
function createPlayer()
{
$player = new t2dAnimatedSprite()
{
scenegraph = t2dscene;
};
//$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($playerLayer);
$player.setGroup($playerGroup);
$player.setCollisionMasks(BIT($platformGroup), BIT($platformLayer));
$player.setCollisionPolyCustom(4, "-0.2 -0.5 0.2 -0.5 0.2 1.0 -0.2 1.0");
$player.setSize("16 16");
$player.setMaxLinearVelocity(250);
$player.runSpeed = 40;
$player.airSpeed = 16;
$player.jumpHeight = 10;
$player.maxRunSurfaceAngle = 35;
$player.setInventory = 0;
$playerStandState = new ScriptObject() { animation = playerStandAnimation; };
$playerStandRunState = new ScriptObject() { animation = playerStandRunAnimation; };
$playerRunState = new ScriptObject() { animation = playerRunAnimation; };
$playerRunStandState = new ScriptObject() { animation = playerRunStandAnimation; };
$playerStandJumpState = new ScriptObject() { animation = playerStandJumpAnimation; };
$playerRunJumpState = new ScriptObject() { animation = playerRunJumpAnimation; };
$playerStandJumpFallState = new ScriptObject() { animation = playerStandJumpFallAnimation; };
$playerRunJumpFallState = new ScriptObject() { animation = playerRunJumpFallAnimation; };
$playerStandFallState = new ScriptObject() { animation = playerStandFallAnimation; };
$playerRunFallState = new ScriptObject() { animation = playerRunFallAnimation; };
$playerFallState = new ScriptObject() { animation = playerFallAnimation; };
$playerFallStandState = new ScriptObject() { animation = playerFallStandAnimation; };
$playerFallRunState = new ScriptObject() { animation = playerFallRunAnimation; };
setInventory();
}
function setInventory()
{
$player.setInventory = 0;
}
function setPlayerState(%state)
{
$player.state = %state;
$player.playAnimation(%state.animation);
}
function collidePlayerPlatform(%normal)
{
%move = $moveRight - $moveLeft;
$runSurface = isRunSurface(%normal, $player.maxRunSurfaceAngle);
if ($runSurface > 0)
{
$player.setLinearVelocityX(%move * $player.runSpeed);
}
if ($player.state == $playerStandState)
{
$player.setLinearVelocityY(0);
}
}
function playerJump()
{
$player.setLinearVelocityY(-10 * $player.jumpHeight);
}
function updatePlayer()
{
updatePlayerAnimation();
%move = $moveRight - $moveLeft;
if ($runSurface < 0)
{
%speed = $player.getLinearVelocityX();
if (%move)
{
if (((%speed * %move) <= 0) || (mAbs(%speed) < $player.airSpeed))
$player.setLinearVelocityX(%move * $player.airSpeed);
}
}
}
More___________________________________________________________________________________
07/15/2006 (9:10 pm)
Try this : function createPlayer()
{
$player = new t2dAnimatedSprite()
{
scenegraph = t2dscene;
};
//$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($playerLayer);
$player.setGroup($playerGroup);
$player.setCollisionMasks(BIT($platformGroup), BIT($platformLayer));
$player.setCollisionPolyCustom(4, "-0.2 -0.5 0.2 -0.5 0.2 1.0 -0.2 1.0");
$player.setSize("16 16");
$player.setMaxLinearVelocity(250);
$player.runSpeed = 40;
$player.airSpeed = 16;
$player.jumpHeight = 10;
$player.maxRunSurfaceAngle = 35;
$player.setInventory = 0;
$playerStandState = new ScriptObject() { animation = playerStandAnimation; };
$playerStandRunState = new ScriptObject() { animation = playerStandRunAnimation; };
$playerRunState = new ScriptObject() { animation = playerRunAnimation; };
$playerRunStandState = new ScriptObject() { animation = playerRunStandAnimation; };
$playerStandJumpState = new ScriptObject() { animation = playerStandJumpAnimation; };
$playerRunJumpState = new ScriptObject() { animation = playerRunJumpAnimation; };
$playerStandJumpFallState = new ScriptObject() { animation = playerStandJumpFallAnimation; };
$playerRunJumpFallState = new ScriptObject() { animation = playerRunJumpFallAnimation; };
$playerStandFallState = new ScriptObject() { animation = playerStandFallAnimation; };
$playerRunFallState = new ScriptObject() { animation = playerRunFallAnimation; };
$playerFallState = new ScriptObject() { animation = playerFallAnimation; };
$playerFallStandState = new ScriptObject() { animation = playerFallStandAnimation; };
$playerFallRunState = new ScriptObject() { animation = playerFallRunAnimation; };
setInventory();
}
function setInventory()
{
$player.setInventory = 0;
}
function setPlayerState(%state)
{
$player.state = %state;
$player.playAnimation(%state.animation);
}
function collidePlayerPlatform(%normal)
{
%move = $moveRight - $moveLeft;
$runSurface = isRunSurface(%normal, $player.maxRunSurfaceAngle);
if ($runSurface > 0)
{
$player.setLinearVelocityX(%move * $player.runSpeed);
}
if ($player.state == $playerStandState)
{
$player.setLinearVelocityY(0);
}
}
function playerJump()
{
$player.setLinearVelocityY(-10 * $player.jumpHeight);
}
function updatePlayer()
{
updatePlayerAnimation();
%move = $moveRight - $moveLeft;
if ($runSurface < 0)
{
%speed = $player.getLinearVelocityX();
if (%move)
{
if (((%speed * %move) <= 0) || (mAbs(%speed) < $player.airSpeed))
$player.setLinearVelocityX(%move * $player.airSpeed);
}
}
}
More___________________________________________________________________________________
#5
{
$player.setPosition(%pos);
$camera.setTrapObject(true);
setPlayerState($playerStandState);
$player.setConstantForce(0 SPC $gravity, true);
}
function updatePlayerAnimation()
{
// Grab the desired direction of movement.
%move = $moveRight - $moveLeft;
%jump = $jump;
// The state machine. The current state of the player is determined, and
// based on some rules that can change that state, the state is updated.
switch ($player.state)
{
// Standing still.
case $playerStandState:
// If suddenly the player is not a surface, start falling.
if ($runSurface < 0)
setPlayerState($playerStandFallState);
// If we want to jump, do it.
else if (%jump)
setPlayerState($playerStandJumpState);
// And if we want to move, do that.
else if (%move)
setPlayerState($playerStandRunState);
// Starting to run.
case $playerStandRunState:
// If the player ran off a cliff or some such, start falling.
if ($runSurface < 0)
setPlayerState($playerRunFallState);
// If we want to jump, do it.
else if (%jump)
setPlayerState($playerRunJumpState);
// And if this animation is done, the player is in a full fledged run.
else if ($player.getIsAnimationFinished())
setPlayerState($playerRunState);
// Running.
case $playerRunState:
// Ran off an edge. We need to make sure this is an actual edge, and
// not just the top of an incline or set of stairs.
if ($runSurface < 0)
{
// Save the current y velocity so it can be reset.
%yVel = $player.getLinearVelocityY();
// Cast a collision downward to see if there is a platform close
// by.
$player.setLinearVelocityY(100);
%collision = $player.castCollision(0.1);
$player.setLinearVelocityY(%yVel);
// No collision, so the player is actually at an edge.
if (%collision $= "")
setPlayerState($playerRunFallState);
// There was a collision. Now make sure it was with a runnable
// platform.
else
{
// Grab the object.
%obj = getWord(%collision, 0);
// Grab the surface normal.
%normal = getWords(%collision, 4, 5);
// If the collision is not with a runnable platform, fall.
if ((%obj.getGroup() != $platformGroup) ||
(isRunSurface(%normal, $player.maxRunSurfaceAngle) < 1))
{
setPlayerState($playerRunFallState);
}
}
}
// Jump.
else if (%jump)
setPlayerState($playerRunJumpState);
// Stop moving.
else if (!%move)
setPlayerState($playerRunStandState);
// Stop running.
case $playerRunStandState:
// Fall.
if ($runSurface < 0)
setPlayerState($playerRunFallState);
// Jump.
else if (%jump)
setPlayerState($playerStandJumpState);
// Start running again.
else if (%move)
setPlayerState($playerRunState);
// Stop completely.
else if ($player.getIsAnimationFinished())
setPlayerState($playerStandState);
// Standing jump.
case $playerStandJumpState:
// Once the standing jump animation is finished, the player actually
// jumps.
if ($player.getIsAnimationFinished())
{
setPlayerState($playerStandJumpFallState);
playerJump();
}
// Running jump.
case $playerRunJumpState:
// Once the running jump animation is finished, the player actually
// jumps.
if ($player.getIsAnimationFinished())
{
setPlayerState($playerRunJumpFallState);
playerJump();
}
// Fall from a standing jump.
case $playerStandJumpFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Fall from a running jump.
case $playerRunJumpFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Falling.
case $playerFallState:
// If suddenly the player hit the ground...
if ($runSurface > 0)
{
// If it is moving, start running.
if (%move)
setPlayerState($playerFallRunState);
// Otherwise, stand still.
else
setPlayerState($playerFallStandState);
}
// Standing still landing.
case $playerFallStandState:
if ($player.getIsAnimationFinished())
setPlayerState($playerStandState);
// Running landing.
case $playerFallRunState:
if ($player.getIsAnimationFinished())
setPlayerState($playerRunState);
// Standing still fall.
case $playerStandFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Running fall.
case $playerRunFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
}
// Set the orientation of the player based on the direction it is moving.
// If it is not moving, the direction will not change and thus will face
// in the last direction of movement.
if (%move < 0)
$player.setFlip(true, false);
else if (%move > 0)
$player.setFlip(false, false);
}
its for a older version but may help
07/15/2006 (9:11 pm)
Function resetPlayer(%pos){
$player.setPosition(%pos);
$camera.setTrapObject(true);
setPlayerState($playerStandState);
$player.setConstantForce(0 SPC $gravity, true);
}
function updatePlayerAnimation()
{
// Grab the desired direction of movement.
%move = $moveRight - $moveLeft;
%jump = $jump;
// The state machine. The current state of the player is determined, and
// based on some rules that can change that state, the state is updated.
switch ($player.state)
{
// Standing still.
case $playerStandState:
// If suddenly the player is not a surface, start falling.
if ($runSurface < 0)
setPlayerState($playerStandFallState);
// If we want to jump, do it.
else if (%jump)
setPlayerState($playerStandJumpState);
// And if we want to move, do that.
else if (%move)
setPlayerState($playerStandRunState);
// Starting to run.
case $playerStandRunState:
// If the player ran off a cliff or some such, start falling.
if ($runSurface < 0)
setPlayerState($playerRunFallState);
// If we want to jump, do it.
else if (%jump)
setPlayerState($playerRunJumpState);
// And if this animation is done, the player is in a full fledged run.
else if ($player.getIsAnimationFinished())
setPlayerState($playerRunState);
// Running.
case $playerRunState:
// Ran off an edge. We need to make sure this is an actual edge, and
// not just the top of an incline or set of stairs.
if ($runSurface < 0)
{
// Save the current y velocity so it can be reset.
%yVel = $player.getLinearVelocityY();
// Cast a collision downward to see if there is a platform close
// by.
$player.setLinearVelocityY(100);
%collision = $player.castCollision(0.1);
$player.setLinearVelocityY(%yVel);
// No collision, so the player is actually at an edge.
if (%collision $= "")
setPlayerState($playerRunFallState);
// There was a collision. Now make sure it was with a runnable
// platform.
else
{
// Grab the object.
%obj = getWord(%collision, 0);
// Grab the surface normal.
%normal = getWords(%collision, 4, 5);
// If the collision is not with a runnable platform, fall.
if ((%obj.getGroup() != $platformGroup) ||
(isRunSurface(%normal, $player.maxRunSurfaceAngle) < 1))
{
setPlayerState($playerRunFallState);
}
}
}
// Jump.
else if (%jump)
setPlayerState($playerRunJumpState);
// Stop moving.
else if (!%move)
setPlayerState($playerRunStandState);
// Stop running.
case $playerRunStandState:
// Fall.
if ($runSurface < 0)
setPlayerState($playerRunFallState);
// Jump.
else if (%jump)
setPlayerState($playerStandJumpState);
// Start running again.
else if (%move)
setPlayerState($playerRunState);
// Stop completely.
else if ($player.getIsAnimationFinished())
setPlayerState($playerStandState);
// Standing jump.
case $playerStandJumpState:
// Once the standing jump animation is finished, the player actually
// jumps.
if ($player.getIsAnimationFinished())
{
setPlayerState($playerStandJumpFallState);
playerJump();
}
// Running jump.
case $playerRunJumpState:
// Once the running jump animation is finished, the player actually
// jumps.
if ($player.getIsAnimationFinished())
{
setPlayerState($playerRunJumpFallState);
playerJump();
}
// Fall from a standing jump.
case $playerStandJumpFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Fall from a running jump.
case $playerRunJumpFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Falling.
case $playerFallState:
// If suddenly the player hit the ground...
if ($runSurface > 0)
{
// If it is moving, start running.
if (%move)
setPlayerState($playerFallRunState);
// Otherwise, stand still.
else
setPlayerState($playerFallStandState);
}
// Standing still landing.
case $playerFallStandState:
if ($player.getIsAnimationFinished())
setPlayerState($playerStandState);
// Running landing.
case $playerFallRunState:
if ($player.getIsAnimationFinished())
setPlayerState($playerRunState);
// Standing still fall.
case $playerStandFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
// Running fall.
case $playerRunFallState:
if ($player.getIsAnimationFinished())
setPlayerState($playerFallState);
}
// Set the orientation of the player based on the direction it is moving.
// If it is not moving, the direction will not change and thus will face
// in the last direction of movement.
if (%move < 0)
$player.setFlip(true, false);
else if (%move > 0)
$player.setFlip(false, false);
}
its for a older version but may help
#6
07/15/2006 (9:11 pm)
That code uses the mannequin player
#7
Okay, I plugged the code into my player.cs and when it compiles I get no errors (YAY!) but the only thing that loads is my tilemap background image, there is no player mannequin in sight. I can successfully load up a static image of the mannequin but how to I tell the engine to load up the specific player.png animated sprite?
here's part of my create player() function...
//-----------------------------------------------------------------------------
// Generate Player.
//-----------------------------------------------------------------
function createPlayer()
{
//$player = new t2dStaticSprite()
$player = new t2dAnimatedSprite()
{
scenegraph = SceneWindow2D.getScenegraph();
};
//$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
...
heres part of my datablocks cs.
new t2dImageMapDatablock(playerImageMap)
{
imageMode = "cell";
cellWidth = 128;
cellHeight = 128;
inset = 5;
imageName = "~/data/images/player";
};
What could I be doing wrong? How do I point the engine to the correct file named "player.png?"
07/15/2006 (10:56 pm)
Thanks! I'll give this a try.Okay, I plugged the code into my player.cs and when it compiles I get no errors (YAY!) but the only thing that loads is my tilemap background image, there is no player mannequin in sight. I can successfully load up a static image of the mannequin but how to I tell the engine to load up the specific player.png animated sprite?
here's part of my create player() function...
//-----------------------------------------------------------------------------
// Generate Player.
//-----------------------------------------------------------------
function createPlayer()
{
//$player = new t2dStaticSprite()
$player = new t2dAnimatedSprite()
{
scenegraph = SceneWindow2D.getScenegraph();
};
//$player.setImageMap(playerImageMap);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
...
heres part of my datablocks cs.
new t2dImageMapDatablock(playerImageMap)
{
imageMode = "cell";
cellWidth = 128;
cellHeight = 128;
inset = 5;
imageName = "~/data/images/player";
};
What could I be doing wrong? How do I point the engine to the correct file named "player.png?"
Torque Owner Corey Punches