I have a problem with the Scrolling World posted by SPower.
I have an Archer (not the CameraFollower) that is spawning Arrows(neither the CameraFollower). Those Arrows are supposed to fly parable wise. I am pretty sure that the Code added below is right, because it works in a scenario without the ScrollWorld and ScrollActor without any problems. It even works, when the CameraFollower is moving (it actually needs to change its x-y-Coordinates, means move(1) and then move(-1) in the same act does not count), but somehow not, when he is not.
When the CameraFollower is moving the "setGloabalLocation()" method works just fine and the Arrow is "teleported" to where he is supposed to. When he is not moving, the Arrow is "teleported" to somewhere outside the BigSpace.
From what I know it has to do something with the ScrollActor Class, because this is the only way the Archer or Arrow and the CameraFollower are connected.
The Part in the Archer, where the Arrow is added to the World:
The Part in the Arrow, where he gets the variables from the Archer:
The Part where the Arrow moves:
/**
* This method spwans Arrows whenever there is an Arrow in Range and the int "round" is greater than 2.
* The new Arrow gets the x-y-Coordinates from the first entry of the "getObjectsInRange"-list and the GlobalX- and
* GlobalY-Coordinates from the Archer (as his Spawning-Point) and is spwaned at exactly this point.
*/
public void dropArrows()
{
round++;
if (getObjectsInRange(1000,Dirt.class).size() > 0)
{
Dirt thisDirt = getObjectsInRange(1000,Dirt.class).get(0);
xZ = thisDirt.getGlobalX();
yZ = thisDirt.getGlobalY();
if ((round > 2) && ( xZ - getX() != 0))
{
getWorld().addObject(new Arrow(getGlobalX(),getGlobalY(), xZ , yZ),getGlobalX(),getGlobalY());
round = 0;
}
}
}
/**
* Here the Arrow gets his velocity, depending on where the target is. It also gives the variables, gotten from the
* Archer, new names.
*/
public Arrow(double spawnX, double spawnY, double xZ, double yZ)
{
if (xZ < spawnX)
{
velocity = -3;
}
else
{
velocity = 3;
}
AxZ = xZ;
AyZ = yZ;
AspawnX = spawnX;
AspawnY = spawnY;
}
/**
* This void lets the Arrow move in a parable. It first calculates the Variables a,b and c in different voids, then
* determines the next x-y-Coordinates.
*/
public void act()
{
if (!isInAir)
{
a = getParabela(AxZ,AyZ,yS);
b = getParabelb(AxZ,AyZ,yS,a);
c = getParabelc(AxZ,AyZ,yS,a,b);
isInAir = true;
}
xLocation = getGlobalX() + velocity;
yLocation = (int) (a*(xLocation*xLocation)+b*xLocation+c);
turnTowardsGlobalLocation(xLocation,yLocation);
setGlobalLocation(xLocation,yLocation);
System.out.println("Location:"+xLocation+","+yLocation);
}
