Jump to content

  • Log In with Google      Sign In   
  • Create Account

MrTheFoxx

Member Since 25 Nov 2011
Offline Last Active Feb 27 2012 02:18 PM

Posts I've Made

In Topic: Frame Independent Motion/Animation in SDL

30 January 2012 - 02:31 PM

Thanks! So I can set up some if statements and if the time elapsed is equal to or beyond a certain value, change the animation frame for the player and/or the position? Good. Thanks! :)

In Topic: Frame Independent Motion/Animation in SDL

29 January 2012 - 01:41 PM

I found something about that while I was Googling, but it has to do with C++. The timer class likely isn't present in C itself because C++ is C with Classes. There has to be some other alternative in C to what is available in C++. Or maybe I could program my own time calculator and integrate that in there...

In Topic: Screen Cropping SDL

15 January 2012 - 06:13 PM

Ahh! Thanks for clearing that up. It really helped out. This should be all that I need in order to get scrolling working and everything, so thank you very much! :) Selecting the green arrow next to "Was this post useful to you?" increases your Reputation, right? I'll be doing that now on all of your posts here. Thanks again! :)

In Topic: Screen Cropping SDL

15 January 2012 - 05:37 PM

Minimal Example:
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
int main() {
    SDL_Event kbrd;
    SDL_Surface *player, *screen, *background;
    player=IMG_Load("dot.png");
    background=IMG_Load("white.png");
    SDL_Rect playerpos;
    playerpos.x=-100;
    playerpos.y=-100;
    printf("Original Position: %d, %d\n",playerpos.x,playerpos.y);
    SDL_Init( SDL_INIT_EVERYTHING );
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    unsigned char done=0, keydown=0, direction;
    while(!done) {
	    while ( SDL_PollEvent(&kbrd) ) {
		    switch (kbrd.type) {
    case SDL_KEYDOWN:
#ifndef _WIN32_WCE
	 if ( kbrd.key.keysym.sym == SDLK_ESCAPE ) {
	  done = 1;
	 }
	 else if(kbrd.key.keysym.sym==SDLK_RIGHT) {
		 direction=1;
		 keydown=1;
	 }
	 else if(kbrd.key.keysym.sym==SDLK_LEFT) {
		 direction=2;
		 keydown=1;
	 }
	 else if(kbrd.key.keysym.sym==SDLK_UP) {
		 direction=3;
		 keydown=1;
	 }
	 else if(kbrd.key.keysym.sym==SDLK_DOWN) {
		 direction=4;
		 keydown=1;
	 }

#else
	 done = 1;
#endif
	 break;
			    case SDL_KEYUP:
				    if(kbrd.key.keysym.sym==SDLK_RIGHT || kbrd.key.keysym.sym==SDLK_LEFT || kbrd.key.keysym.sym==SDLK_UP || kbrd.key.keysym.sym==SDLK_DOWN) keydown=0;
				    break;
    case SDL_QUIT:
	 done = 1;
	 break;
    default:
	 break;
		    }
	    }
	    SDL_BlitSurface(background,NULL,screen,NULL);
	    SDL_BlitSurface(player,NULL,screen,&playerpos);
	    SDL_Flip(screen);
	    if(keydown && direction==1) playerpos.x+=4;
	    if(keydown && direction==2) playerpos.x-=4;
	    if(keydown && direction==3) playerpos.y-=4;
	    if(keydown && direction==4) playerpos.y+=4;
	    if(keydown) printf("%d, %d\n",playerpos.x,playerpos.y);
    }
    return(0); }
I used a 640x480 solid white image for white.png and a 16x16 red dot for dot.png. Substitute these with whatever you have readily available. The player (dot) will not go into negative coordinates no matter what. (Controls are Up, Down, Left, and Right on the keyboard.) I was hoping there would be a way to take the "world space co-ordinates" and crop out the "screen space co-ordinates" without having to shift objects around.

In Topic: Screen Cropping SDL

15 January 2012 - 04:36 PM

So what you are saying is to go through and subtract the camera position from the position of each object on the map, from the player to the blocks that make up the stage itself? This is something that I have tried, but the objects that go under 0, 0 as their coordinates (-100, 0, for example) are rendered at the origin (upper-left-hand corner) of the screen. Perhaps adding if(object[c].x-camera.x<0 || object[c].y-camera.y<0) display[c]=0; (with display[c]=0; disabling displaying the tile) will make the object not be displayed if it has such coordinates? Did I read your response incorrectly, or are we on the same page? Move all of the objects in the map in order to have camera movement? And does the solution I posted work? Thank you for your time. I appreciate it.

EDIT: The problem with the code I posted is that if an object goes beyond 0, 0, it isn't displayed. This is good, but part of the object would be cut off each time. Time for another diagram.
Posted Image
And because the block can't be drawn from before 0 so it is only halfway into or halfway out of the viewing area, that is not an option. How would I avoid such a problem? I know I could put a black border around the screen, but there has to be some other way to do this. Do you understand what I'm saying? Even if the X Coordinate of a block is -400, it is still displayed at 0 on the screen for its X Coordinate.

Again, thanks. I apologize if I am not being easy to understand.



EDIT #2: I made a program prints the X Coordinate of an object after setting that to -400 and it prints 0 instead. I'm going to conclude that object.x and object.y are unsigned integers and therefore can't be set equal to anything less than 0 and be expected to work. All of this is how I got lost in the first place when trying to figure out how to get a camera working. Please give me your insight. Thanks.

PARTNERS