SOLVED. Different background size causes problems with footstep sounds?

Started by Akril15, Sat 22/02/2014 21:40:56

Previous topic - Next topic

Akril15

Hello,

I'm working on a 640x400 game in AGS 3.2.1 and have run into an unusual problem.

In this game, the main character has footstep sounds that change depending on the surface she is walking on. The script for doing this looks like this:

Global script (repeatedly_execute_always):
Code: ags

if (GetWalkableAreaAt(player.x, player.y)==1 || GetWalkableAreaAt(player.x, player.y)==2) steps_dirt();
    //if player is on walkable area 1 or 2, have her footsteps sound like she's walking in dirt

 if (GetWalkableAreaAt(player.x, player.y)==3) steps_grass();
    //if player is on walkable area 2, have her footsteps sound like she's walking in grass

 if (GetWalkableAreaAt(player.x, player.y)==4) steps_stone();
  //stone


steps_dirt, steps_grass, etc. point to the contents of this script (footsteps.asc):
Code: ags

function ros_steps_grass() {
  //setting footsteps (grass)
ViewFrame *frame = Game.GetViewFrame(1, 0, 4); //change the GetViewFrame numbers to the character's view, loop and frame number
frame.LinkedAudio=aGrass1; //change to number of first grass footstep sound effect -- this is the sound that's going to be assigned to the frame in the previous line of code
frame = Game.GetViewFrame(1, 0, 4); //every one of these lines represents a frame where a footstep sound is supposed to play -- keep changing them to match the way they appear in the character's view, and make sure to include both left AND right footsteps!
frame.LinkedAudio=aGrass1;
frame = Game.GetViewFrame(1, 1, 4);
frame.LinkedAudio=aGgrass1;
frame = Game.GetViewFrame(1, 2, 4);
///and so on...
    }


This code works fine in every room except one. The main character's footstep sounds won't play in this room. If she enters this room from an adjacent screen, her footsteps do have sounds, but the sounds are carried over from the walkable area she was on in the previous room. I've tried to figure out what the problem is, and strangely, it seems like the only thing that might be causing this problem is the size of the room's background -- it's 640x750, while the rest of the game's rooms are 640x400. I've tried replacing this room with a 640x400 background, and voila -- the footstep sounds play without any problem.

Is there any real correlation between the lack of footstep sounds and the larger background, or might there be something else that's causing this?

EDIT: Solved! It looks like the different size was causing some confusion with the game's coordinates, but I was able to get around this problem by putting some lines like this in the room's repeatedly_execute_always section:
Code: ags

 if (player.y>648) steps_dirt();
 else steps_stone();

Khris

First of all, you can do this:

Code: ags
  int wa = GetWalkableAreaAt(...);
  if (wa == 1 || wa == 2) steps(aGrass1);
  else if (wa == 3) steps(aDirt1);

// in footsteps.asc:
function steps(AudioClip *ac) {
  ..
  frame.LinkedAudio = ac;
  ...
}


On to why your footsteps were off: GetWalkableAreaAt uses screen coordinates (which is a bad choice for multiple reasons, imo, but that's another story).
You need to do this:
Code: ags
  int wa = GetWalkableAreaAt(player.x - GetViewportX(), player.y - GetViewportY());

SMF spam blocked by CleanTalk