I'm quite new to AS3, and I'm trying to make a game that has a sort of RPG-like movement, I've been using PixelPerfectCollisionDetection by Troy Gilbert and I'm using that to detect collisions between the character and a movie clip of a collision map, it works quite well, but I don't know how to actually add the collisions in, I've been trying to do the thing where when you hit the collision area, you move the opposite direction back, but it looks dodgy and can make the character go through the wall if you hit a different key, so I'm trying to find a way to make better collisions. The whole movement is based on moving the whole map with the collision map, the charSpeed represents how fast the map moves, and if the collision map hits the character, it detects the collision, the collision is detected from a different class file which dispatches an event if a collision has been made, this class recieves it and turns a boolean to true, it also dispatches an event for no collision so it turns it false. Here is the code for the movement and collision:
public function runControlTime(timeHandlerEvents:TimeHandlerEvents):void
{
if (charUp == true)
{
if (collisionDetected)
{
y -= charSpeed;
}
else
{
y += charSpeed;
}
}
if (charDown == true)
{
if (collisionDetected)
{
y += charSpeed;
}
else
{
y -= charSpeed;
}
}
if (charLeft == true)
{
if (collisionDetected)
{
x += charSpeed;
}
else
{
x -= charSpeed;
}
}
if (charRight == true)
{
if (collisionDetected)
{
x -= charSpeed;
}
else
{
x += charSpeed;
}
}
}