Ok thanks a tonne for the help it works beatifully I have now ran into another problem. I created a function to neaten up thr program and keep it more modular. Now the program is error free and runs the function that controls background scrolling however the sprites seem to have frozen and will no longer run. I was wondering if you could take another look and see if im missing something obious? Thanks again!
#include "DarkGDK.h"
void ScrollingBG(int &, float, float, float, float, float&);
void DarkGDK()
{
dbSetDisplayMode(1024,700,32);
int scroll = 1;
float Ycoord = 0;
float Ycoord2 = 1400;
float Ycoord3 = - 800;
float Ycoord4 = - 1000;
float speed = 2;
void ScrollingBG(int &, float, float, float, float, float&);
dbSyncOn();
while (LoopGDK())
{
ScrollingBG(scroll, Ycoord, Ycoord2, Ycoord3, Ycoord4, speed);
}
}
void ScrollingBG(int &scroll, float Ycoord, float Ycoord2, float Ycoord3, float Ycoord4, float &speed)
{
dbLoadImage("Background_Main.png", 1);
dbLoadImage("Background_Main_2.png", 2);
dbLoadImage("Background_Second.png", 3);
dbLoadImage("Background_Third.png", 4);
if(dbSpaceKey())
{
scroll = 0;
}
else
{
scroll = 1;
}
dbSprite(1,0,Ycoord,1);
dbSprite(2,0,Ycoord2,2);
dbSprite(3,-1,Ycoord3,3);
dbSprite(4,0,Ycoord4,4);
// Scrolling loop for the background
if(scroll == 1)
{
Ycoord = Ycoord - speed;
}
if (scroll == 0)
{
Ycoord = Ycoord - (speed/4);
}
if(scroll == 1)
{
Ycoord2 = Ycoord2 - speed;
}
if (scroll == 0)
{
Ycoord2 = Ycoord2 - (speed/4);
}
// Resets the backgorund
if(Ycoord2 <= 0)
{
Ycoord2 = 1400;
Ycoord = 0;
}
// Scrolling loop for the vertical bars
if (scroll == 1)
{
Ycoord3 = Ycoord3 + speed;
}
if (scroll == 0)
{
Ycoord3 = Ycoord3 + (speed/4);
}
if (Ycoord3 > 400)
{
Ycoord3 = -800;
}
// Scrolling loop for the horizontal bars
if (scroll == 1)
{
Ycoord4 = Ycoord4 + (speed*2);
}
if (scroll == 0)
{
Ycoord4 = Ycoord4 + ((speed*2)/4);
}
if (Ycoord4 > 400)
{
Ycoord4 = -1400;
}
dbSync();
}