I’ve been making an RTS game (but dealing with small problems first), and I’ve been looking at forums to solve things that I have some trouble with, until now.
Whenever I get my player character to move towards at least half way before switching to camera mode, the background will scroll out of range for some reason (that only occurs on the left hand side, but I can simply re-enter the background).
This also occured when I tried to implement a different character movement where acceleration and deceleration is involved.
here are my files if anyone wants to check:
www.mediafire.com/?5v8gya5u93h7nr2
I’ll just post the background code 1st. But the reason why I posted that file is that I’m not sure if the orblem is only in the background class.
[code block]
Third times the charm! (I wish I can edit my post in these forums… Would’ve saved me a lot of posts…)
package{
import flash.display.MovieClip;
import flash.events.Event;
public class Background extends MovieClip{
public function Background(){
}
public function Moving(xSpeed:Number, xDistance:Number){
if (xSpeed == -ControlledUnit.speedFactor){
if (Gameplay2.controlledUnit.x <= (Gameplay2.gameWidth/2)) {
if (Math.abs(this.x) > 0) {
this.x -= xDistance*xSpeed;
if (PixelPerfectCollisionDetection.isColliding(Gameplay2.targetDummy, Gameplay2.controlledUnit, this, true))
{
if (Gameplay2.controlledUnit.y >= (Gameplay2.targetDummy.y - 5) && Gameplay2.controlledUnit.y <= (Gameplay2.targetDummy.y + 5)){
this.x += xDistance*xSpeed;
Gameplay2.targetDummy.x += xDistance*xSpeed;
Gameplay2.enemy.x += xDistance*xSpeed;
Gameplay2.mainBase.x += xDistance*xSpeed;
}
}
Gameplay2.controlledUnit.x -= xDistance*xSpeed;
Gameplay2.targetDummy.x -= xDistance*xSpeed;
Gameplay2.enemy.x -= xDistance*xSpeed;
Gameplay2.mainBase.x -= xDistance*xSpeed;
}
}
}else{
if (Gameplay2.controlledUnit.x >= (Gameplay2.gameWidth/2)) {
if (Math.abs(this.x) < this.width - Gameplay2.gameWidth-4) {
this.x -= xDistance*xSpeed;
if (PixelPerfectCollisionDetection.isColliding(Gameplay2.targetDummy, Gameplay2.controlledUnit, this, true))
{
if (Gameplay2.controlledUnit.y >= (Gameplay2.targetDummy.y - 5) && Gameplay2.controlledUnit.y <= (Gameplay2.targetDummy.y + 5)){
this.x += xDistance*xSpeed;
Gameplay2.targetDummy.x += xDistance*xSpeed;
Gameplay2.enemy.x += xDistance*xSpeed;
Gameplay2.mainBase.x += xDistance*xSpeed;
}
}
Gameplay2.controlledUnit.x -= xDistance*xSpeed;
Gameplay2.targetDummy.x -= xDistance*xSpeed;
Gameplay2.enemy.x -= xDistance*xSpeed;
Gameplay2.mainBase.x -= xDistance*xSpeed;
}
}
}
}
public function cameraMoving(xSpeed:Number, xDistance:Number){
if (xSpeed == -ControlledUnit.speedFactor){
trace("1) " + this.x);
if (Math.abs(this.x) > 0) {
this.x -= xDistance*xSpeed;
Gameplay2.controlledUnit.x -= xDistance*xSpeed;
Gameplay2.targetDummy.x -= xDistance*xSpeed;
Gameplay2.enemy.x -= xDistance*xSpeed;
Gameplay2.mainBase.x -= xDistance*xSpeed;
trace("2) " + this.x);
}
}else{
if (Math.abs(this.x) < this.width - Gameplay2.gameWidth-4) {
this.x -= xDistance*xSpeed;
Gameplay2.controlledUnit.x -= xDistance*xSpeed;
Gameplay2.targetDummy.x -= xDistance*xSpeed;
Gameplay2.enemy.x -= xDistance*xSpeed;
Gameplay2.mainBase.x -= xDistance*xSpeed;
}
}
}
}
}
And this is the actual line of code I suspect has some problems (I think)
public function cameraMoving(xSpeed:Number, xDistance:Number){
if (xSpeed == -ControlledUnit.speedFactor){
if (Math.abs(this.x) > 0) {
this.x -= xDistance*xSpeed;
Gameplay2.controlledUnit.x -= xDistance*xSpeed;
Gameplay2.targetDummy.x -= xDistance*xSpeed;
Gameplay2.enemy.x -= xDistance*xSpeed;
Gameplay2.mainBase.x -= xDistance*xSpeed;
}else{
trace("hello!");
}
}else{