Sidescroller help?
Hi, People
Im Currently making a side scroller game for IOS and im using this peice of code on my main timeline..
<AS>
import flash.events.*;
import flash.utils.*;
import flash.display.MovieClip;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import Classes.GlobalVaribles;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
stop();
var vy:Number;
var vx:Number;
var inAir:Boolean = false;
MoneyText.text = "£: " + GlobalVaribles.Money;
// set Default Values
vy = 0;
vx = 0;
Player.gotoAndStop(1);
// stage focus;
stage.focus = stage;
// add event listeners
this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
// Movement Event Listeners;
Attack_btn.addEventListener(TouchEvent.TOUCH_BEGIN,AttackBtnBegin);
Attack_btn.addEventListener(TouchEvent.TOUCH_END,AttackBtnEnd);
JumpBtn.addEventListener(TouchEvent.TOUCH_TAP,JumpBtnHandler);
Change_DirectionRight.addEventListener(TouchEvent.TOUCH_BEGIN, RightBtnBegin);
Change_DirectionRight.addEventListener(TouchEvent.TOUCH_END, RightBtnEnd);
Change_DirectionLeft.addEventListener(TouchEvent.TOUCH_BEGIN, LeftBtnBegin);
Change_DirectionLeft.addEventListener(TouchEvent.TOUCH_END, LeftBtnEnd);
function enterFrameHandler(e:Event):void
{
// Apply Gravity on Player
vy += 2;
// move player
Player.x += vx;
Player.y += vy;
// process collisions
processCollisions();
//scroll the stage
scrollStage();
//Check if player in air
if (! Player.hitTestObject(Boundries))
{
inAir = true;
}
if (Player.hitTestObject(Boundries))
{
inAir = false;
}
}
function scrollStage():void
{
Boundries.x += (stage.stageWidth * 0.5) - Player.x;
Player.x = stage.stageWidth * 0.5;
Boundries.y += (stage.stageHeight * 0.5) - Player.y;
Player.y = stage.stageHeight * 0.5;
}
function processCollisions():void
{
// when player is falling
if (vy>0)
{
// process Collisions with boundries
var collision:Boolean = false;
if (Boundries.hitTestPoint(Player.x,Player.y,true))
{
collision = true;
}
if (collision)
{
while (collision)
{
Player.y -= 0.1;
collision = false;
if (Boundries.hitTestPoint(Player.x,Player.y,true))
{
collision = true;
}
}
vy = 0;
}
}
}
function JumpBtnHandler(e:TouchEvent):void
{
if (! inAir)
{
vy -= 20;
vx += 5;
vx -= 5;
}
}
function RightBtnBegin(e:TouchEvent):void
{
addEventListener(Event.ENTER_FRAME, RunRight);
Player.scaleX = 1;
}
function RightBtnEnd(e:TouchEvent):void
{
removeEventListener(Event.ENTER_FRAME, RunRight);
}
function LeftBtnBegin(e:TouchEvent):void
{
addEventListener(Event.ENTER_FRAME, RunLeft);
Player.scaleX = -1;
}
function LeftBtnEnd(e:TouchEvent):void
{
removeEventListener(Event.ENTER_FRAME, RunLeft);
}
function RunRight(e:Event):void
{
Player.x += 12;
}
function RunLeft(e:Event):void
{
Player.x -= 12;
}
function AttackBtnBegin(e:TouchEvent):void
{
Player.gotoAndStop(2);
}
function AttackBtnEnd(e:TouchEvent):void
{
Player.gotoAndStop(1);
}
stage.addEventListener(Event.ENTER_FRAME,HealthActions);
function HealthActions(e:Event):void
{
if (GlobalVaribles.Health == 5)
{
Health_Container.Health1.visible = true;
Health_Container.Health2.visible = true;
Health_Container.Health3.visible = true;
Health_Container.Health4.visible = true;
Health_Container.Health5.visible = true;
}
if (GlobalVaribles.Health == 4)
{
Health_Container.Health1.visible = true;
Health_Container.Health2.visible = true;
Health_Container.Health3.visible = true;
Health_Container.Health4.visible = true;
Health_Container.Health5.visible = false;
}
if (GlobalVaribles.Health == 3)
{
Health_Container.Health1.visible = true;
Health_Container.Health2.visible = true;
Health_Container.Health3.visible = true;
Health_Container.Health4.visible = false;
Health_Container.Health5.visible = false;
}
if (GlobalVaribles.Health == 2)
{
Health_Container.Health1.visible = true;
Health_Container.Health2.visible = true;
Health_Container.Health3.visible = false;
Health_Container.Health4.visible = false;
Health_Container.Health5.visible = false;
}
if (GlobalVaribles.Health == 1)
{
Health_Container.Health1.visible = true;
Health_Container.Health2.visible = false;
Health_Container.Health3.visible = false;
Health_Container.Health4.visible = false;
Health_Container.Health5.visible = false;
}
if (GlobalVaribles.Health == 0)
{
Health_Container.Health1.visible = false;
Health_Container.Health2.visible = false;
Health_Container.Health3.visible = false;
Health_Container.Health4.visible = false;
Health_Container.Health5.visible = false;
trace("Dead");
}
}
<AS>
And im getting a bug where when you go into a wall you automatically stand above it..
seen in this video
Also i would like to know a better way to side scroll well follow the character than
Boundries.x += (stage.stageWidth * 0.5) - Player.x;
Player.x = stage.stageWidth * 0.5;
Boundries.y += (stage.stageHeight * 0.5) - Player.y;
Player.y = stage.stageHeight * 0.5;
