• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

SOLVED "Ghost" Pixels Above the Camera

Gonix

Member
I'm making a platform game with camera travels. I have a problem with vertical camera travels, "ghost" pixels from the screen stay above the screen. They disapear when the camera stops moving verticaly.This not happend when the camera is moving from up to down. I did not find any topics about that kind of problem.
To move the camera, I use an object that is followed by the camera, so I move the object to move the camera.
 

Attachments

Did you try to move the camera in the end step, or somewhere you're 100% sure all your other movement code has already run this step?
If you follow an object that's just about to move away, it can cause issues like this
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
To move the camera, I use an object that is followed by the camera, so I move the object to move the camera.
Post the code! This issue, as mentioned in the post above mine, is usually caused by the camera updating before the rest of the objects and elements in the view are updated, so it's a step "behind" the actual position of everything. Seeing your code and the events that it's in will help us to help you resolve the problem. :)
 

Gonix

Member
My game is a kind of roguelike, so the rooms are placed differently between each runs. The room coordinates are stored in INI files.


Create:
GML:
ini_open("RoomsPos.ini");
x = ini_read_real("room11","xr","1")
y = ini_read_real("room11","yr","1")
actualRoomX = x;
actualRoomY = y;
XCamSpeed = 0;
YCamSpeed = 0;
trnsTrgtX = 0;
trnsTrgtY = 0;
transitioANY = false;
transitioN = false;
transitioO = false;
transitioS = false;
transitioE = false;
ini_close()
Step:
GML:
trgtLeft = keyboard_check(vk_numpad4);
trgtRight = keyboard_check(vk_numpad6);
trgtUp = keyboard_check(vk_numpad8);
trgtDown = keyboard_check(vk_numpad2);
x = x + XCamSpeed;
y = y + YCamSpeed;
if (trgtRight)
{
    x += 2;
}
if (trgtLeft)
{
    x -= 2;
}
if (trgtDown)
{
    y += 2;
}
if (trgtUp)
{
    y -= 2;
}
End step:
GML:
//Transition E
if (transitioE = 1)
{
    XCamSpeed = 12;
    ini_open("RoomsPos.ini")
    trnsTrgtX = ini_read_real("room24","xr","1");
    trnsTrgtY = ini_read_real("room24","yr","1");
    ini_close()
    if (x >= actualRoomX + 768)
    {
        transitioE = 2;
    }
}
if (transitioE = 2)
{
    oPlayer.x = trnsTrgtX - (384-64)
    oPlayer.y = trnsTrgtY - 18.5
    XCamSpeed = 0;
    x = trnsTrgtX - 768
    y = trnsTrgtY
    transitioE = 3;
}

if (transitioE = 3)
{
    XCamSpeed = 12;
    if (x >= trnsTrgtX)
    {
        XCamSpeed = 0;
        transitioE = 0;
        transitioANY = false;
        actualRoomX = x;
        actualRoomY = y;
    }
}

//Transition O
if (transitioO = 1)
{
    XCamSpeed = -12;
    ini_open("RoomsPos.ini")
    trnsTrgtX = ini_read_real("room11","xr","1");
    trnsTrgtY = ini_read_real("room11","yr","1");
    ini_close()
    if (x <= actualRoomX - 768)
    {
        transitioO = 2;
    }
}
if (transitioO = 2)
{
    oPlayer.x = trnsTrgtX + (384-64)
    oPlayer.y = trnsTrgtY - 18.5
    XCamSpeed = 0;
    x = trnsTrgtX + 768
    y = trnsTrgtY
    transitioO = 3;
}

if (transitioO = 3)
{
    XCamSpeed = -12;
    if (x <= trnsTrgtX)
    {
        XCamSpeed = 0;
        transitioO = 0;
        transitioANY = false;
        actualRoomX = x;
        actualRoomY = y;
    }
}

//Transition N
if (transitioN = 1)
{
    YCamSpeed = -8;
    ini_open("RoomsPos.ini")
    trnsTrgtX = ini_read_real("room31","xr","1");
    trnsTrgtY = ini_read_real("room31","yr","1");
    ini_close()
    if (y <= actualRoomY - 416)
    {
        transitioN = 2;
        oPlayer.vspd = 0;
    }
}
if (transitioN = 2)
{
    oPlayer.y = trnsTrgtY + (208-64)
    oPlayer.x = trnsTrgtX
    YCamSpeed = 0;
    x = trnsTrgtX
    y = trnsTrgtY + 416
    transitioN = 3;
}

if (transitioN = 3)
{
    YCamSpeed = -8;
    if (y <= trnsTrgtY)
    {
        YCamSpeed = 0;
        transitioN = 0;
        transitioANY = false;
        actualRoomX = x;
        actualRoomY = y;
    }
}
the room coordinates are the center of the rooms

The step are keys to manually move the camera

And to make the camera following the camera object, i'm using the "follow object" in room settings ==> Viewport and cameras

I enabled "clear viewport background" , and now there is just black , instead of ghost images, so i think it can be a problem with the following of the background to the camera
 

Attachments

You do set the cam speed in the end step, but in the step event, you use
GML:
x = x + XCamSpeed;
y = y + YCamSpeed;
.

Also not too shabby about opening and closing ini files (3 times the same file, by the way) every step, but hey, whatever floats your boat, I guess!

One of my ex-girlfriend did that:
-> Open the fridge
->get the bread
-> close the fridge
->put the bread on the counter
-> Open the fridge
->get the jam
-> close the fridge
->put the jam on the counter
-> Open the fridge
->get the milk
-> close the fridge
->put the milk on the counter

That drove me nuts, man, I swear! šŸ˜‚
 

Gonix

Member
You do set the cam speed in the end step, but in the step event, you use
GML:
x = x + XCamSpeed;
y = y + YCamSpeed;
If i don't set it here, the camera just do not move.
Do you mean i should put it at the start of the end step?
 
Last edited:
If i don't set it here, the camera just do not move.
Do you mean i should put it at the start of the end step?
if the camera follows this instance, you should set it's position AFTER you set the camera speed, otherwise it's position will be affected by the previous step's camera speed. Hence why it looks ok when you don't move.
 

Gonix

Member
Thanks you M.Slow Fingers!
I solved the issue by not using the follow object from the room editor, but the fonction
GML:
camera_set_view_pos()
The new step:
Code:
trgtLeft = keyboard_check(vk_numpad4);
trgtRight = keyboard_check(vk_numpad6);
trgtUp = keyboard_check(vk_numpad8);
trgtDown = keyboard_check(vk_numpad2);

x = x + XCamSpeed;
y = y + YCamSpeed;

camera_set_view_pos(oGame.cameraPosition,x-384,y-208)
if (trgtRight)
{
    x += 2;
}
if (trgtLeft)
{
    x -= 2;
}
if (trgtDown)
{
    y += 2;
}
if (trgtUp)
{
    y -= 2;
}
 
I suggest you start with the basics

EDIT: Yeah, it was not making sense at all if you try and set the camera speed both in code and in the editor, plus the fact you adjust the position as per the coded speed...wasn't going to work good.
I would just leave the editor stuff alone, for views and cameras, unless it's a static thing.
 
Top