MGSting
Member
The game I'm developing in GM 1.4 is a sidescrolling beat-em-up like Final Fight and as such, it has a sidescrolling camera that stops moving in a battle area. Here's the code for the camera object:
And here's the code for the battle region, which is the source of the problem.
To test the engine, I created a 3000 x 768 room with two battle zones, having three enemies placed within them. The first one works like it should, but the second causes the camera to shake like crazy. I tried making the room an extra 700 pixels large and spacing both battle zones 768 pixels apart, it didn't work. I tried making the second battle zone 768 pixels away from the end of the room, it didn't work. I think there might be an error in the code that would cause this instead of where I place the battle zones within the room. I could just have one battle zone per room in the finished product, however since enemies don't respawn that would make for a boring experience.
Thanks in advance.
Code:
Create Event
==========================
view_object[0] = OBJ_Camera;
view_vborder[0] = 384;
view_hborder[0] = 512;
view_visible[0] = true;
x = OBJ_Player.x;
y = OBJ_Player.y;
TargetX = x;
TargetY = y;
State = "Player";
MoveSpeed = 15;
Code:
Step Event
=======================================
MyBR = instance_nearest(x,y,OBJ_BattleRegion);
switch State{
case "Player":
TargetX = OBJ_Player.x;
TargetY = OBJ_Player.y;
if(MyBR.IsActive == true){
State = "Region";
}
break;
case "Region":
var MinX = OBJ_BattleRegion.LeftEdge+512;
var MaxX = OBJ_BattleRegion.RightEdge-512;
var MinY = OBJ_BattleRegion.TopEdge+384;
var MaxY = OBJ_BattleRegion.BottomEdge-384;
TargetX = clamp(OBJ_Player.x,MinX,MaxX);
TargetY = clamp(OBJ_Player.y,MinY,MaxY);
if(MyBR.IsActive == false || distance_to_object(OBJ_BattleRegion) > 0){
State = "Player";
}
break;
}
if(distance_to_point(TargetX,TargetY) < MoveSpeed){
x = TargetX;
y = TargetY;
speed = 0;
}else{
move_towards_point(TargetX,TargetY,MoveSpeed);
}
Code:
Create Event
=========================================
IsActive = false;
RegionHeight = sprite_height;
RegionWidth = sprite_width;
LeftEdge = x-RegionWidth/2;
RightEdge = x+RegionWidth/2;
TopEdge = y-RegionHeight/2;
BottomEdge = y+RegionHeight/2;
HasEnemies = false;
Code:
Step Event
========================================
if(instance_exists(OBJ_Enemy) && point_in_rectangle(OBJ_Enemy.x, OBJ_Enemy.y,LeftEdge,TopEdge,RightEdge,BottomEdge)){
HasEnemies = true;
}else{
HasEnemies = false;
IsActive = false;
}
Thanks in advance.