Game Development Community

Problem with the Fish Game tutorial (Movement on PlayerFish class)

by steve targett · in Game Design and Creative Issues · 05/03/2012 (9:19 pm) · 2 replies

Hi, I am creating a fish game and following the Torque 2D tutorial to create it and my code is the exact same as stated so it should work but it does not.

I have created a player.cs file which has been executed in the main code correctly and the code is as follows:

// Creates the player class function
function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer = %this;
//$toggle = 0
moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerUpStop();");
moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerUpStop();");
}

// Creates the moving functions for each key
function fishPlayerUp()
{$FishPlayer.setLinearVelocityY(-15);}

function fishPlayerDown()
{$FishPlayer.setLinearVelocityY(15);}

function fishPlayerLeft()
{$FishPlayer.setLinearVelocityX(-30);
$FishPlayer.setFlipX(true);}

function fishPlayerRight()
{$FishPlayer.setLinearVelocityX(30);
$FishPlayer.setFlipX(false);}

// Creates the stop moving functions for each key
function fishPlayerUpStop()
{$FishPlayer.setLinearVelocityY(0);}

function fishPlayerDownStop()
{$FishPlayer.setLinearVelocityY(0);}

function fishPlayerLeftStop()
{$FishPlayer.setLinearVelocityX(0);}

function fishPlayerRightStop()
{$FishPlayer.setLinearVelocityX(0);}

I have checked it over countless times and I can't figure out why it won't work because it should do as stated by the tutorial. Thanks for any help.

About the author

Recent Threads


#1
05/04/2012 (11:55 am)
Try looking for a console.log file, that should get generated when you run the routine. If there's a syntax error, it should note it in there.
#2
05/04/2012 (1:00 pm)
@steve - You have a logic error. In each of the bindCmd functions you have "fishPlayerUpStop", instead of the other functions that correspond to your fish movement. Looks like a copy + paste error.