Hi, I’m having problems creating a side scroller platform game.
I can get it to either side scroll or get the character to move and work with collisions, not both. I’ve had problems with the character disappearing from the screen etc.
I’ve got to a point at the moment where there are no compiler errors or reference errors and the character is in the right place, and it even changes its state when the left and right arrows are pressed to point in the right direction. However, the character doesn’t move.
Here is my Level class
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.Point;
import flash.display.Sprite;
public class DungeonOne_Manager extends MovieClip
{
private var _levelOneHalfWidth:uint;
private var _levelOneHalfHeight:uint;
private var _playerHalfWidth:uint;
private var _playerHalfHeight:uint;
private var edgeDistance:uint;
public var player:MovieClip;
public var background_mc:MovieClip;
//Variables required for scrolling
private var _rightInnerBoundary:Number
= (stage.stageWidth * 0.5) + (stage.stageWidth * 0.25);
private var _leftInnerBoundary:Number
= (stage.stageWidth * 0.5) - (stage.stageWidth * 0.25);
private var _topInnerBoundary:Number
= (stage.stageHeight * 0.5) - (stage.stageHeight * 0.25);
private var _bottomInnerBoundary:Number
= (stage.stageHeight * 0.5) + (stage.stageHeight * 0.25);
public function DungeonOne_Manager()
{
edgeDistance = (stage.stageHeight / 2) + (stage.stageHeight / 4);
addChild(player);
player.setX = 100;
player.setY = 350;
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addChild(background_mc);
}
private function onAddedToStage(event:Event):void
{
//Add event listeners
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
private function onRemovedFromStage(event:Event):void
{
//Remove the onEnterFrame event if
//this object is removed from the stage
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
trace("Dungeon removed");
}
//Most of game logic is programmed into the
//onEnterFrame event handler
private function onEnterFrame(event:Event):void
{
//Update the lander
player.update();
//Scrolling
//Stop player at inner boundary edges
if (player.xPos < _leftInnerBoundary)
{
player.setX = _leftInnerBoundary;
_rightInnerBoundary
= (stage.stageWidth * 0.5) + (stage.stageWidth * 0.25);
background_mc.x -= player.vx;
}
else if (player.xPos + player.width > _rightInnerBoundary)
{
player.setX = _rightInnerBoundary - player.width;
_leftInnerBoundary
= (stage.stageWidth * 0.5) - (stage.stageWidth * 0.25);
background_mc.x -= player.vx;
}
if (player.yPos < _topInnerBoundary)
{
player.setY = _topInnerBoundary;
_bottomInnerBoundary
= (stage.stageHeight * 0.5) + (stage.stageHeight * 0.25);
background_mc.y -= player.vy;
}
else if (player.yPos + player.height > _bottomInnerBoundary)
{
player.setY = _bottomInnerBoundary - player.height;
_topInnerBoundary
= (stage.stageHeight * 0.5) - (stage.stageHeight * 0.25);
background_mc.y -= player.vy;
}
//Stop Background_mc at stage edges
if (background_mc.x + background_mc.width < stage.stageWidth)
{
background_mc.x = stage.stageWidth - background_mc.width;
_rightInnerBoundary = stage.stageWidth;
}
else if (background_mc.x > 0)
{
background_mc.x = 0;
_leftInnerBoundary = 0;
}
if (background_mc.y > 0)
{
background_mc.y = 0;
_topInnerBoundary = 0;
}
else if (background_mc.y + background_mc.height < stage.stageHeight)
{
background_mc.y = stage.stageHeight - background_mc.height;
_bottomInnerBoundary = stage.stageHeight;
}
}
//8. Pulic methods that other classes can use to
//check for collisions with objects in the game
//A. Allow the wall objects to check for a collison
//with the player
public function checkCollisionWithPlayer(wall:MovieClip)
{
if (player != null)
{
Collision.block(player, wall);
}
}
public function checkCollisionWithBG(background_mc:MovieClip)
{
if (player != null)
{
Collision.block(player, background_mc);
}
}
}
}
Sorry, I realise its a lot of code, I’ve taken out everything irrelevent to what i’m trying to achieve.
It’s really irritating because there are no errors and i dont know where to start on trying to look for them.
If someone could take a look at my code and maybe see where my problem lies, I’d really appreciate it.
Thankyou!