• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
DominicHughes

Problem with animation after right key press in SDL?

0 posts in this topic

Hello I'm trying to fix this graphical problem but I don't know how to code the fix and I don't even know If I'm correct on my solution but I will go ahead and tell you the problem and some ideas to why I think its happening but moving onto the problem.



[u]The Problem[/u]
When I press the right arrow key and blit surfaces to the screen it doesn't do it one at a time but instead all blit surfaces inside the if right key statement go on the screen at once


[u]Why is it happening?[/u]
It's because of the main while loop I think.



But I was wondering how could I set the bliting so that it blits images one at a time so that it won't mess up the application or cause flickering or any other graphical glitch.

Here's my code

[CODE]
/////////////////////////////
//Main Libary
/////////////////////////////
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
/////////////////////////////
//Other Files
#include "CollisionFunction.h"
/////////////////////////////
#define SCREEN_HEIGHT 640
#define SCREEN_WIDTH 480
/////////////////////////////

SDL_Rect OrangeGhostKnightRect;
//Main Rectangles
SDL_Rect LevelOneRect;
SDL_Rect GroundOneRect;
SDL_Rect GroundTwoRect;
SDL_Rect GroundThreeRect;
SDL_Rect GroundFourRect;
//Mario Rect
SDL_Rect MarioRect;
//Water Rects
SDL_Rect WaterRect;
SDL_Rect WaterRect2;
SDL_Rect WaterRect3;
SDL_Rect WaterGroundRect;

//Storage Rectangles
SDL_Rect StorageRect[12];

//BoundingBox
SDL_Rect BoundingBox[2];

//Timer Rect
SDL_Rect TimerTextRect;
//Weather Rect
SDL_Rect BubbleGumCloudRect;
//////////////////////////////////////////////////
//Orange Ghost Knight Logic
/////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

int LevelOneFunction(void *unused)
{
Uint8 *keystate = SDL_GetKeyState(NULL);
////////////////////////////////////////////////////////////////////////////////
//Color Selections
Uint32 RedColor =SDL_MapRGB(Screen->format,255,0,0);
Uint32 OrangeColor =SDL_MapRGB(Screen->format,255,100,0);
Uint32 BlackColor =SDL_MapRGB(Screen->format,0,0,0);
Uint32 GreyColor = SDL_MapRGB(Screen->format,192,192,192);
Uint32 MintGreenColor = SDL_MapRGB(Screen->format,39,216,176);
Uint32 LightOliveGreenColor = SDL_MapRGB(Screen->format,135,179,77);
//SDL COLOR Colors
SDL_Color WhiteColor = {255,255,255};
////////////////////////////////////////////////////////////////////////////////
////////////////////////
//Storage Rect Positions
///////////////////////
StorageRect[1].x = 0;
StorageRect[1].y = 0;
StorageRect[2].x = 0;
StorageRect[2].y = 380;
StorageRect[3].x = 0;
StorageRect[3].y = 310;
StorageRect[4].x = 0;
StorageRect[4].y = 360;
StorageRect[5].x = 0;
StorageRect[5].y = 400;
StorageRect[6].x = 320;
StorageRect[6].y = 400;
StorageRect[7].x = 580;
StorageRect[7].y = 400;
StorageRect[10].x = 400;
StorageRect[10].y = 320;
StorageRect[11].y = -200;
StorageRect[12].x = 5;
///////////////////////////////
//BoundingBox 1 Values
BoundingBox[1].x =160;
BoundingBox[1].y =360;
BoundingBox[1].w = 60;
BoundingBox[1].h = 108;
//BoundingBox 2 Values
BoundingBox[2].x =300;
BoundingBox[2].y =300;
BoundingBox[2].w = 60;
BoundingBox[2].h = 120;

//Mario Rect Values
MarioRect.x = 0;
MarioRect.y = 0;
//LevelOneBG Values
LevelOneRect.x = 0;
LevelOneRect.y = 0;
//PurpleAmal Rock 1 Values
GroundOneRect.x = 0;
GroundOneRect.y = 0;
////////////////////////////

//Bool Variable
bool done = false;
//Event Creation
SDL_Event event;
while(!done)
{ /////////////////////////////////////////
//Logic
////////////////////////////////////////
StorageRect[11].x += 1;
StorageRect[10].x += 1;
//Movements of BoundingBoxes

if(StorageRect[3].x > SCREEN_WIDTH)
{
StorageRect[3].x -=20;
StorageRect[2].x -=3;
StorageRect[6].x -=3;
StorageRect[1].x -=10;
}

////////////////////////////
//Collision Boxes
////////////////////////////
if(Check_Collision(MarioRect,GroundOneRect))
{
StorageRect[3].y -= 5;
}

if(Check_Collision(MarioRect,BoundingBox[1]))
{
StorageRect[3].y += 6;
}

if(StorageRect[10].x == 400)
{
StorageRect[10].x += 40;

}

if(StorageRect[10].x == 480)
{
StorageRect[10].x -=40;
}

//////////////////////////////////////
//Drawing
/////////////////////////////////////


LevelOneRect = StorageRect[1];
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);

WaterGroundRect = StorageRect[5];
SDL_BlitSurface(WaterGroundSurf,NULL,Screen,&WaterGroundRect);

GroundOneRect = StorageRect[2];
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);

GroundTwoRect = StorageRect[6];
SDL_BlitSurface(GroundTwoBG,NULL,Screen,&GroundTwoRect);

GroundThreeRect = StorageRect[7];
SDL_BlitSurface(GroundThreeBG,NULL,Screen,&GroundThreeRect);

//If user doesn't press right key on keyboard
if(keystate[SDLK_RIGHT])
{
MarioRect = StorageRect[3];
SDL_BlitSurface(SuperMarioWalkSurf[1],NULL,Screen,&MarioRect);

MarioRect = StorageRect[3];
SDL_BlitSurface(SuperMarioWalkSurf[2],NULL,Screen,&MarioRect);

MarioRect = StorageRect[3];
SDL_BlitSurface(SuperMarioWalkSurf[3],NULL,Screen,&MarioRect);


//Movements of actual visual objects
StorageRect[3].x +=5;
StorageRect[3].y += 5;
StorageRect[1].x -=6;
StorageRect[2].x -=2;
StorageRect[4].x -=1;
StorageRect[5].x -= 4;
StorageRect[6].x -=2;
StorageRect[7].x -=2;
BoundingBox[2].x -=2;
}

//If user doesn't press right key on keyboard
else if(!keystate[SDLK_RIGHT])
{
MarioRect = StorageRect[3];
SDL_BlitSurface(SuperMarioWalkSurf[1],NULL,Screen,&MarioRect);
}

OrangeGhostKnightRect = StorageRect[10];
SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
BubbleGumCloudRect = StorageRect[11];
SDL_BlitSurface(BubbleGumCloudSurf,NULL,Screen,&BubbleGumCloudRect);
SDL_BlitSurface(Text,NULL,Screen,&TimerTextRect);

////////////////////////////////////////////////////
//While continous events are running in event
////////////////////////////////////////////////////
while(SDL_PollEvent(&event))
{
//allow to be able to switch events
switch(event.type)
{
//if user presses on close
case SDL_QUIT:
//Close Application
return 0;

//break case
break;
//SWITCH EVENT TYPE
}
/////////
//POLL
/////////
}

//////////////////////////////////////
//END OF THE MAIN WHILE LOOP
/////////////////////////////////////
//Update Screen

SDL_Flip(Screen);

}

/////////////////////////////////////

//DONT KNOW
//COULD BE THE RIGHT POINT

}
////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
[/CODE]


If anyone has any answers of any kind and or helpful advice please do say
0

Share this post


Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]anyone[/left][/size][/font][/color]
0

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0