SlideShare a Scribd company logo
1 of 9
Download to read offline
Following are the changes mentioned in bold in order to obtain the required result and stop
scrolling in the background.
#include "SDL/SDL.h"
#include
//The attributes of the screen can be defined as follows
const int SCN_WIDTH = 640;
const int SCN_HEIGHT = 480;
const int SCN_BPP = 32;
//BPP defines bits per pixel
SDL_Surface* Background = NULL;
SDL_Surface* SpriteImage = NULL;
SDL_Surface* Backbuffer = NULL;
int SpriteFrame = 0;
int FrameCounter = 0;
const int MaxSpriteFrame = 12;
const int FrameDelay = 2;
int BackgroundX = 0;
SDL_Surface* LoadImage(char* fileName);
bool LoadFiles();
void FreeFiles();
void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y);
void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width,
int height, int frame);
bool ProgramIsRunning();
int main(int argc, char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("Failed to initialize SDL! ");
return 0;
}
Backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Image Animation", NULL);
if(!LoadFiles())
{
printf("Failed to load all files! ");
FreeFiles();
SDL_Quit();
return 0;
}
while(ProgramIsRunning())
{
//Update's the sprites frame
FrameCounter++;
if(FrameCounter > FrameDelay)
{
FrameCounter = 0;
SpriteFrame++;
}
if(SpriteFrame > MaxSpriteFrame)
SpriteFrame = 0;
//Background scrolling can be removed from this position
//Render the scene
DrawImage(Background,Backbuffer, BackgroundX, 0);
DrawImage(Background,Backbuffer, BackgroundX+800, 0);
DrawImageFrame(SpriteImage, Backbuffer, 350,250, 150, 120, SpriteFrame);
SDL_Delay(20);
SDL_Flip(Backbuffer);
}
FreeFiles();
SDL_Quit();
return 0;
}
SDL_Surface* LoadImage(char* fileName)
{
SDL_Surface* imageLoaded = NULL;
SDL_Surface* processedImage = NULL;
imageLoaded = SDL_LoadBMP(fileName);
if(imageLoaded != NULL)
{
processedImage = SDL_DisplayFormat(imageLoaded);
SDL_FreeSurface(imageLoaded);
if(processedImage != NULL)
{
//Here we map the color key
Uint32 colorKey = SDL_MapRGB(processedImage->format, 0, 0xFF, 0xFF);
//Now, set all the pixels of color R 0,G 0*FF,B 0*FF to be transparent
SDL_SetColorKey(processedImage, SDL_SRCCOLORKEY, colorKey);
}
}
return processedImage;
}
bool LoadFiles()
{
Background = LoadImage("graphics/background.bmp");
if(Background == NULL)
return false;
SpriteImage = LoadImage("graphics/bat.bmp");
//The file should be preloaded and linked with the required libraries in SDL
if(SpriteImage == NULL)
return false;
else
return true;
}
void FreeFiles()
{
SDL_FreeSurface(Background);
SDL_FreeSurface(SpriteImage);
}
void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y)
//A temporary rectangle is used to hold the offsets
{
SDL_Rect destRect;
//Giving the offsets to the rectangle
destRect.x = x;
destRect.y = y;
//Blit the surface
SDL_BlitSurface(image, NULL, destSurface, &destRect);
}
//Here, we need to start the main function:
int main(int argc,char** args)
//Now, initialize all SDL subsystems
if (SDL_Init( SDL_INIT_EVERYTHING ) == -1)
{
return 1;
}
//SDL sysystems are things like video,timers,audio etc which are the individual engine
components used to
make a game
void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width,
int height, int frame)
{
SDL_Rect destRect;
destRect.x = x;
destRect.y = y;
int columns = image->w/width;
SDL_Rect sourceRect;
sourceRect.y = (frame/columns)*height;
sourceRect.x = (frame%columns)*width;
sourceRect.w = width;
sourceRect.h = height;
SDL_BlitSurface(image, &sourceRect, destSurface, &destRect);
}
bool ProgramIsRunning()
{
SDL_Event event;
bool running = true;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
running = false;
}
return running;
}
Solution
Following are the changes mentioned in bold in order to obtain the required result and stop
scrolling in the background.
#include "SDL/SDL.h"
#include
//The attributes of the screen can be defined as follows
const int SCN_WIDTH = 640;
const int SCN_HEIGHT = 480;
const int SCN_BPP = 32;
//BPP defines bits per pixel
SDL_Surface* Background = NULL;
SDL_Surface* SpriteImage = NULL;
SDL_Surface* Backbuffer = NULL;
int SpriteFrame = 0;
int FrameCounter = 0;
const int MaxSpriteFrame = 12;
const int FrameDelay = 2;
int BackgroundX = 0;
SDL_Surface* LoadImage(char* fileName);
bool LoadFiles();
void FreeFiles();
void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y);
void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width,
int height, int frame);
bool ProgramIsRunning();
int main(int argc, char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("Failed to initialize SDL! ");
return 0;
}
Backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Image Animation", NULL);
if(!LoadFiles())
{
printf("Failed to load all files! ");
FreeFiles();
SDL_Quit();
return 0;
}
while(ProgramIsRunning())
{
//Update's the sprites frame
FrameCounter++;
if(FrameCounter > FrameDelay)
{
FrameCounter = 0;
SpriteFrame++;
}
if(SpriteFrame > MaxSpriteFrame)
SpriteFrame = 0;
//Background scrolling can be removed from this position
//Render the scene
DrawImage(Background,Backbuffer, BackgroundX, 0);
DrawImage(Background,Backbuffer, BackgroundX+800, 0);
DrawImageFrame(SpriteImage, Backbuffer, 350,250, 150, 120, SpriteFrame);
SDL_Delay(20);
SDL_Flip(Backbuffer);
}
FreeFiles();
SDL_Quit();
return 0;
}
SDL_Surface* LoadImage(char* fileName)
{
SDL_Surface* imageLoaded = NULL;
SDL_Surface* processedImage = NULL;
imageLoaded = SDL_LoadBMP(fileName);
if(imageLoaded != NULL)
{
processedImage = SDL_DisplayFormat(imageLoaded);
SDL_FreeSurface(imageLoaded);
if(processedImage != NULL)
{
//Here we map the color key
Uint32 colorKey = SDL_MapRGB(processedImage->format, 0, 0xFF, 0xFF);
//Now, set all the pixels of color R 0,G 0*FF,B 0*FF to be transparent
SDL_SetColorKey(processedImage, SDL_SRCCOLORKEY, colorKey);
}
}
return processedImage;
}
bool LoadFiles()
{
Background = LoadImage("graphics/background.bmp");
if(Background == NULL)
return false;
SpriteImage = LoadImage("graphics/bat.bmp");
//The file should be preloaded and linked with the required libraries in SDL
if(SpriteImage == NULL)
return false;
else
return true;
}
void FreeFiles()
{
SDL_FreeSurface(Background);
SDL_FreeSurface(SpriteImage);
}
void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y)
//A temporary rectangle is used to hold the offsets
{
SDL_Rect destRect;
//Giving the offsets to the rectangle
destRect.x = x;
destRect.y = y;
//Blit the surface
SDL_BlitSurface(image, NULL, destSurface, &destRect);
}
//Here, we need to start the main function:
int main(int argc,char** args)
//Now, initialize all SDL subsystems
if (SDL_Init( SDL_INIT_EVERYTHING ) == -1)
{
return 1;
}
//SDL sysystems are things like video,timers,audio etc which are the individual engine
components used to
make a game
void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width,
int height, int frame)
{
SDL_Rect destRect;
destRect.x = x;
destRect.y = y;
int columns = image->w/width;
SDL_Rect sourceRect;
sourceRect.y = (frame/columns)*height;
sourceRect.x = (frame%columns)*width;
sourceRect.w = width;
sourceRect.h = height;
SDL_BlitSurface(image, &sourceRect, destSurface, &destRect);
}
bool ProgramIsRunning()
{
SDL_Event event;
bool running = true;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
running = false;
}
return running;
}

More Related Content

Similar to Following are the changes mentioned in bold in order to obtain the r.pdf

Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202Mahmoud Samir Fayed
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019UA Mobile
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Eugene Kurko
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScriptSam Cartwright
 
How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?Flutter Agency
 
Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)Korhan Bircan
 
The Ring programming language version 1.2 book - Part 35 of 84
The Ring programming language version 1.2 book - Part 35 of 84The Ring programming language version 1.2 book - Part 35 of 84
The Ring programming language version 1.2 book - Part 35 of 84Mahmoud Samir Fayed
 
CUDA Deep Dive
CUDA Deep DiveCUDA Deep Dive
CUDA Deep Divekrasul
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...DroidConTLV
 
Tema3_Introduction_to_CUDA_C.pdf
Tema3_Introduction_to_CUDA_C.pdfTema3_Introduction_to_CUDA_C.pdf
Tema3_Introduction_to_CUDA_C.pdfpepe464163
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming APIMax Kleiner
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdffootstatus
 
Java ME - 05 - Game API
Java ME - 05 - Game APIJava ME - 05 - Game API
Java ME - 05 - Game APIAndreas Jakl
 

Similar to Following are the changes mentioned in bold in order to obtain the r.pdf (20)

Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Arduino
ArduinoArduino
Arduino
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?
 
Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)Useful Tools for Making Video Games - Irrlicht (2008)
Useful Tools for Making Video Games - Irrlicht (2008)
 
The Ring programming language version 1.2 book - Part 35 of 84
The Ring programming language version 1.2 book - Part 35 of 84The Ring programming language version 1.2 book - Part 35 of 84
The Ring programming language version 1.2 book - Part 35 of 84
 
CUDA Deep Dive
CUDA Deep DiveCUDA Deep Dive
CUDA Deep Dive
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Dip iit workshop
Dip iit workshopDip iit workshop
Dip iit workshop
 
Tema3_Introduction_to_CUDA_C.pdf
Tema3_Introduction_to_CUDA_C.pdfTema3_Introduction_to_CUDA_C.pdf
Tema3_Introduction_to_CUDA_C.pdf
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming API
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
Java ME - 05 - Game API
Java ME - 05 - Game APIJava ME - 05 - Game API
Java ME - 05 - Game API
 

More from anithareadymade

We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdfanithareadymade
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdfanithareadymade
 
ITs both by the way... it depends on the situatio.pdf
                     ITs both by the way... it depends on the situatio.pdf                     ITs both by the way... it depends on the situatio.pdf
ITs both by the way... it depends on the situatio.pdfanithareadymade
 
I believe you are correct. The phase transfer cat.pdf
                     I believe you are correct. The phase transfer cat.pdf                     I believe you are correct. The phase transfer cat.pdf
I believe you are correct. The phase transfer cat.pdfanithareadymade
 
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdf
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdfThere are 7 stages in Software Development LifeCycle. Coming to SDLC.pdf
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdfanithareadymade
 
The correct statements are1. the oxygen atom has a greater attrac.pdf
The correct statements are1. the oxygen atom has a greater attrac.pdfThe correct statements are1. the oxygen atom has a greater attrac.pdf
The correct statements are1. the oxygen atom has a greater attrac.pdfanithareadymade
 
This is a bit complex to answer as we have HCl and NaOH present, the.pdf
This is a bit complex to answer as we have HCl and NaOH present, the.pdfThis is a bit complex to answer as we have HCl and NaOH present, the.pdf
This is a bit complex to answer as we have HCl and NaOH present, the.pdfanithareadymade
 
The possible causative agent is Corynebacterium diptheriaeSore thr.pdf
The possible causative agent is Corynebacterium diptheriaeSore thr.pdfThe possible causative agent is Corynebacterium diptheriaeSore thr.pdf
The possible causative agent is Corynebacterium diptheriaeSore thr.pdfanithareadymade
 
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdf
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdfThe answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdf
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdfanithareadymade
 
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdf
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdfRainfallTest.java import java.util.Arrays; import java.util.Sc.pdf
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdfanithareadymade
 
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdf
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdfby taking p1,p2,p3 as points in cordinate system.. displavement can .pdf
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdfanithareadymade
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfanithareadymade
 
i did not get itSolutioni did not get it.pdf
i did not get itSolutioni did not get it.pdfi did not get itSolutioni did not get it.pdf
i did not get itSolutioni did not get it.pdfanithareadymade
 
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdf
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdfHello!!!!!!! This answer will help you ) H2Se would occur in a .pdf
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdfanithareadymade
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfanithareadymade
 
During meiosis, each member of a pair of genes tends to be randomly .pdf
During meiosis, each member of a pair of genes tends to be randomly .pdfDuring meiosis, each member of a pair of genes tends to be randomly .pdf
During meiosis, each member of a pair of genes tends to be randomly .pdfanithareadymade
 
B parents marital statusSolutionB parents marital status.pdf
B parents marital statusSolutionB parents marital status.pdfB parents marital statusSolutionB parents marital status.pdf
B parents marital statusSolutionB parents marital status.pdfanithareadymade
 
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdf
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdfANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdf
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdfanithareadymade
 
Array- Arrays is a collection of data items with same data type and.pdf
Array- Arrays is a collection of data items with same data type and.pdfArray- Arrays is a collection of data items with same data type and.pdf
Array- Arrays is a collection of data items with same data type and.pdfanithareadymade
 

More from anithareadymade (20)

We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
 
MgO = 2416 = 1.5 .pdf
                     MgO = 2416 = 1.5                               .pdf                     MgO = 2416 = 1.5                               .pdf
MgO = 2416 = 1.5 .pdf
 
ITs both by the way... it depends on the situatio.pdf
                     ITs both by the way... it depends on the situatio.pdf                     ITs both by the way... it depends on the situatio.pdf
ITs both by the way... it depends on the situatio.pdf
 
I believe you are correct. The phase transfer cat.pdf
                     I believe you are correct. The phase transfer cat.pdf                     I believe you are correct. The phase transfer cat.pdf
I believe you are correct. The phase transfer cat.pdf
 
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdf
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdfThere are 7 stages in Software Development LifeCycle. Coming to SDLC.pdf
There are 7 stages in Software Development LifeCycle. Coming to SDLC.pdf
 
The correct statements are1. the oxygen atom has a greater attrac.pdf
The correct statements are1. the oxygen atom has a greater attrac.pdfThe correct statements are1. the oxygen atom has a greater attrac.pdf
The correct statements are1. the oxygen atom has a greater attrac.pdf
 
This is a bit complex to answer as we have HCl and NaOH present, the.pdf
This is a bit complex to answer as we have HCl and NaOH present, the.pdfThis is a bit complex to answer as we have HCl and NaOH present, the.pdf
This is a bit complex to answer as we have HCl and NaOH present, the.pdf
 
The possible causative agent is Corynebacterium diptheriaeSore thr.pdf
The possible causative agent is Corynebacterium diptheriaeSore thr.pdfThe possible causative agent is Corynebacterium diptheriaeSore thr.pdf
The possible causative agent is Corynebacterium diptheriaeSore thr.pdf
 
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdf
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdfThe answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdf
The answer is E) 1,2, and 3.The solubility of a gas in solvents de.pdf
 
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdf
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdfRainfallTest.java import java.util.Arrays; import java.util.Sc.pdf
RainfallTest.java import java.util.Arrays; import java.util.Sc.pdf
 
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdf
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdfby taking p1,p2,p3 as points in cordinate system.. displavement can .pdf
by taking p1,p2,p3 as points in cordinate system.. displavement can .pdf
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
 
i did not get itSolutioni did not get it.pdf
i did not get itSolutioni did not get it.pdfi did not get itSolutioni did not get it.pdf
i did not get itSolutioni did not get it.pdf
 
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdf
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdfHello!!!!!!! This answer will help you ) H2Se would occur in a .pdf
Hello!!!!!!! This answer will help you ) H2Se would occur in a .pdf
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
During meiosis, each member of a pair of genes tends to be randomly .pdf
During meiosis, each member of a pair of genes tends to be randomly .pdfDuring meiosis, each member of a pair of genes tends to be randomly .pdf
During meiosis, each member of a pair of genes tends to be randomly .pdf
 
B parents marital statusSolutionB parents marital status.pdf
B parents marital statusSolutionB parents marital status.pdfB parents marital statusSolutionB parents marital status.pdf
B parents marital statusSolutionB parents marital status.pdf
 
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdf
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdfANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdf
ANSWERS12. B collecting ducts13. B efferent arteriol15. juxtag.pdf
 
Array- Arrays is a collection of data items with same data type and.pdf
Array- Arrays is a collection of data items with same data type and.pdfArray- Arrays is a collection of data items with same data type and.pdf
Array- Arrays is a collection of data items with same data type and.pdf
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 

Recently uploaded (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 

Following are the changes mentioned in bold in order to obtain the r.pdf

  • 1. Following are the changes mentioned in bold in order to obtain the required result and stop scrolling in the background. #include "SDL/SDL.h" #include //The attributes of the screen can be defined as follows const int SCN_WIDTH = 640; const int SCN_HEIGHT = 480; const int SCN_BPP = 32; //BPP defines bits per pixel SDL_Surface* Background = NULL; SDL_Surface* SpriteImage = NULL; SDL_Surface* Backbuffer = NULL; int SpriteFrame = 0; int FrameCounter = 0; const int MaxSpriteFrame = 12; const int FrameDelay = 2; int BackgroundX = 0; SDL_Surface* LoadImage(char* fileName); bool LoadFiles(); void FreeFiles(); void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y); void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width, int height, int frame); bool ProgramIsRunning(); int main(int argc, char* args[]) { if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("Failed to initialize SDL! "); return 0; } Backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE); SDL_WM_SetCaption("Image Animation", NULL); if(!LoadFiles()) {
  • 2. printf("Failed to load all files! "); FreeFiles(); SDL_Quit(); return 0; } while(ProgramIsRunning()) { //Update's the sprites frame FrameCounter++; if(FrameCounter > FrameDelay) { FrameCounter = 0; SpriteFrame++; } if(SpriteFrame > MaxSpriteFrame) SpriteFrame = 0; //Background scrolling can be removed from this position //Render the scene DrawImage(Background,Backbuffer, BackgroundX, 0); DrawImage(Background,Backbuffer, BackgroundX+800, 0); DrawImageFrame(SpriteImage, Backbuffer, 350,250, 150, 120, SpriteFrame); SDL_Delay(20); SDL_Flip(Backbuffer); } FreeFiles(); SDL_Quit(); return 0; } SDL_Surface* LoadImage(char* fileName) { SDL_Surface* imageLoaded = NULL; SDL_Surface* processedImage = NULL; imageLoaded = SDL_LoadBMP(fileName); if(imageLoaded != NULL) { processedImage = SDL_DisplayFormat(imageLoaded);
  • 3. SDL_FreeSurface(imageLoaded); if(processedImage != NULL) { //Here we map the color key Uint32 colorKey = SDL_MapRGB(processedImage->format, 0, 0xFF, 0xFF); //Now, set all the pixels of color R 0,G 0*FF,B 0*FF to be transparent SDL_SetColorKey(processedImage, SDL_SRCCOLORKEY, colorKey); } } return processedImage; } bool LoadFiles() { Background = LoadImage("graphics/background.bmp"); if(Background == NULL) return false; SpriteImage = LoadImage("graphics/bat.bmp"); //The file should be preloaded and linked with the required libraries in SDL if(SpriteImage == NULL) return false; else return true; } void FreeFiles() { SDL_FreeSurface(Background); SDL_FreeSurface(SpriteImage); } void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y) //A temporary rectangle is used to hold the offsets { SDL_Rect destRect; //Giving the offsets to the rectangle destRect.x = x; destRect.y = y; //Blit the surface
  • 4. SDL_BlitSurface(image, NULL, destSurface, &destRect); } //Here, we need to start the main function: int main(int argc,char** args) //Now, initialize all SDL subsystems if (SDL_Init( SDL_INIT_EVERYTHING ) == -1) { return 1; } //SDL sysystems are things like video,timers,audio etc which are the individual engine components used to make a game void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width, int height, int frame) { SDL_Rect destRect; destRect.x = x; destRect.y = y; int columns = image->w/width; SDL_Rect sourceRect; sourceRect.y = (frame/columns)*height; sourceRect.x = (frame%columns)*width; sourceRect.w = width; sourceRect.h = height; SDL_BlitSurface(image, &sourceRect, destSurface, &destRect); } bool ProgramIsRunning() { SDL_Event event; bool running = true; while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) running = false; }
  • 5. return running; } Solution Following are the changes mentioned in bold in order to obtain the required result and stop scrolling in the background. #include "SDL/SDL.h" #include //The attributes of the screen can be defined as follows const int SCN_WIDTH = 640; const int SCN_HEIGHT = 480; const int SCN_BPP = 32; //BPP defines bits per pixel SDL_Surface* Background = NULL; SDL_Surface* SpriteImage = NULL; SDL_Surface* Backbuffer = NULL; int SpriteFrame = 0; int FrameCounter = 0; const int MaxSpriteFrame = 12; const int FrameDelay = 2; int BackgroundX = 0; SDL_Surface* LoadImage(char* fileName); bool LoadFiles(); void FreeFiles(); void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y); void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width, int height, int frame); bool ProgramIsRunning(); int main(int argc, char* args[]) { if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("Failed to initialize SDL! "); return 0; }
  • 6. Backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE); SDL_WM_SetCaption("Image Animation", NULL); if(!LoadFiles()) { printf("Failed to load all files! "); FreeFiles(); SDL_Quit(); return 0; } while(ProgramIsRunning()) { //Update's the sprites frame FrameCounter++; if(FrameCounter > FrameDelay) { FrameCounter = 0; SpriteFrame++; } if(SpriteFrame > MaxSpriteFrame) SpriteFrame = 0; //Background scrolling can be removed from this position //Render the scene DrawImage(Background,Backbuffer, BackgroundX, 0); DrawImage(Background,Backbuffer, BackgroundX+800, 0); DrawImageFrame(SpriteImage, Backbuffer, 350,250, 150, 120, SpriteFrame); SDL_Delay(20); SDL_Flip(Backbuffer); } FreeFiles(); SDL_Quit(); return 0; } SDL_Surface* LoadImage(char* fileName) { SDL_Surface* imageLoaded = NULL; SDL_Surface* processedImage = NULL;
  • 7. imageLoaded = SDL_LoadBMP(fileName); if(imageLoaded != NULL) { processedImage = SDL_DisplayFormat(imageLoaded); SDL_FreeSurface(imageLoaded); if(processedImage != NULL) { //Here we map the color key Uint32 colorKey = SDL_MapRGB(processedImage->format, 0, 0xFF, 0xFF); //Now, set all the pixels of color R 0,G 0*FF,B 0*FF to be transparent SDL_SetColorKey(processedImage, SDL_SRCCOLORKEY, colorKey); } } return processedImage; } bool LoadFiles() { Background = LoadImage("graphics/background.bmp"); if(Background == NULL) return false; SpriteImage = LoadImage("graphics/bat.bmp"); //The file should be preloaded and linked with the required libraries in SDL if(SpriteImage == NULL) return false; else return true; } void FreeFiles() { SDL_FreeSurface(Background); SDL_FreeSurface(SpriteImage); } void DrawImage(SDL_Surface* image, SDL_Surface* destSurface, int x, int y) //A temporary rectangle is used to hold the offsets { SDL_Rect destRect;
  • 8. //Giving the offsets to the rectangle destRect.x = x; destRect.y = y; //Blit the surface SDL_BlitSurface(image, NULL, destSurface, &destRect); } //Here, we need to start the main function: int main(int argc,char** args) //Now, initialize all SDL subsystems if (SDL_Init( SDL_INIT_EVERYTHING ) == -1) { return 1; } //SDL sysystems are things like video,timers,audio etc which are the individual engine components used to make a game void DrawImageFrame(SDL_Surface* image, SDL_Surface* destSurface, int x, int y, int width, int height, int frame) { SDL_Rect destRect; destRect.x = x; destRect.y = y; int columns = image->w/width; SDL_Rect sourceRect; sourceRect.y = (frame/columns)*height; sourceRect.x = (frame%columns)*width; sourceRect.w = width; sourceRect.h = height; SDL_BlitSurface(image, &sourceRect, destSurface, &destRect); } bool ProgramIsRunning() { SDL_Event event; bool running = true; while(SDL_PollEvent(&event))
  • 9. { if(event.type == SDL_QUIT) running = false; } return running; }