Hi, if anyone can find a solution to my problem will be great.
i am using codeblocks 10.05 SDL_image-1.2.12 SDL_ttf-2.0.11 SDL-1.2.14-win32
i am writing a program from scratch and i am a beginner if you want. two main problem affictl my program no compiling error or so ever but perhaphs limitation of code language probably?
1-my program as a login screen that i manage to make it work fantastic for me, but once i arrive the login succesfull i want to have the rid of everything except the screen in order to proceed with the loading of the real game, but this is no possible if i insert a sdl_freesurface or a clean up function the program seem to crash. (segmentation relative to the flipping of the screen for the real game i use different images so it is not a problem of sharing the same image...)
2-i started my game creating a map yes this will be a 2d tile game based, now what i would like to do it is grabbing the map with mouseevent button down and realise it when i relise the left button; and using mousemovement to calculate the offset while the left button it is pressed. probably sdl do not let you to use the two event togheter?
2b if i use only mouse move the map actualy moves but still the screen doesn't update and you can see the drag.
thanks if somebody reply
SDL help with my program
Hi everyone i got this program from one of my friend on internet and it is working for moving as bitmap around (still to adapth to my program) but still seems i can't have the rid of the screen of login if anyone can help please i have the following message
#0 0040350E wrconw::wrconv(this=0x28fe03, screen=0x5f3768, backgroundtwo=0x0, event={type = 5 '\005', active = {type = 5 '\005', gain = 0 '\0', state = 1 '\001'}, key = {type = 5 '\005', which = 0 '\0', state = 1 '\001', keysym = {scancode = 5 '\005', sym = SDLK_UNKNOWN, mod = KMOD_NONE, unicode = 0}}, motion = {type = 5 '\005', which = 0 '\0', state = 1 '\001', x = 261, y = 387, xrel = 0, yrel = 0}, button = {type = 5 '\005', which = 0 '\0', button = 1 '\001', state = 1 '\001', x = 261, y = 387}, jaxis = {type = 5 '\ (C:\wrconv 0.01\wrconv0.01.cpp:88)
#1 00404968 SDL_main(argc=1, args=0x5f2b30) (C:\wrconv 0.01\login.cpp:399)
#2 0040565B console_main(argc=1, argv=0x5f2b30) (./src/main/win32/SDL_win32_main.c:315)
#3 00405718 WinMain(hInst=0x400000, hPrev=0x0, szCmdLine=0x813668 "", sw=10) (./src/main/win32/SDL_win32_main.c:398)
#4 00000000 0x00404fe6 in main() (??:??)
now i post you the code working for moving a bitmmap around with the mouse
#0 0040350E wrconw::wrconv(this=0x28fe03, screen=0x5f3768, backgroundtwo=0x0, event={type = 5 '\005', active = {type = 5 '\005', gain = 0 '\0', state = 1 '\001'}, key = {type = 5 '\005', which = 0 '\0', state = 1 '\001', keysym = {scancode = 5 '\005', sym = SDLK_UNKNOWN, mod = KMOD_NONE, unicode = 0}}, motion = {type = 5 '\005', which = 0 '\0', state = 1 '\001', x = 261, y = 387, xrel = 0, yrel = 0}, button = {type = 5 '\005', which = 0 '\0', button = 1 '\001', state = 1 '\001', x = 261, y = 387}, jaxis = {type = 5 '\ (C:\wrconv 0.01\wrconv0.01.cpp:88)
#1 00404968 SDL_main(argc=1, args=0x5f2b30) (C:\wrconv 0.01\login.cpp:399)
#2 0040565B console_main(argc=1, argv=0x5f2b30) (./src/main/win32/SDL_win32_main.c:315)
#3 00405718 WinMain(hInst=0x400000, hPrev=0x0, szCmdLine=0x813668 "", sw=10) (./src/main/win32/SDL_win32_main.c:398)
#4 00000000 0x00404fe6 in main() (??:??)
now i post you the code working for moving a bitmmap around with the mouse
#include <SDL.h>
const int SCREEN_WIDTH = 320; /* Set the screen width variable */
const int SCREEN_HEIGHT = 240; /* Set the screen height variable */
const int SCREEN_DEPTH = 32; /* Set the screen depth variable */
int main(int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Surface *bitmap;
SDL_Rect offset;
/* Part of bitmap to view */
SDL_Rect bitmap_offset;
SDL_Event event;
bool running = true;
bool mousedown = false;
/* Initialize SDL */
SDL_Init(SDL_INIT_VIDEO);
//SDL_Init(SDL_INIT_EVERYTHING);
/* Initialise the screen, by passing the screen width, height, depth, and surface type */
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
/* set up the screen offset variables, where we will draw the bitmap to */
offset.x = 0;
offset.y = 0;
offset.h = SCREEN_HEIGHT;
offset.w = SCREEN_WIDTH;
/* Part of bitmap to view */
bitmap_offset = offset; /* C++ code */
bitmap = SDL_LoadBMP ("C:/wrconv 0.01/bin/Debug/images/backgroundtwo.bmp");
/* calculate the maximum x and y origin of bitmap to show on screen */
int max_x_origin = bitmap->w - SCREEN_WIDTH;
int max_y_origin = bitmap->h - SCREEN_HEIGHT;
/* Check if bitmap is smaller than window */
if(max_x_origin < 0)
max_x_origin = 0;
if(max_y_origin < 0)
max_y_origin = 0;
/* apply the bitmap to the screen */
SDL_BlitSurface (bitmap, NULL, screen, &offset);
/* update the screen */
SDL_Flip(screen);
while(running)
{
while( SDL_PollEvent( &event ) )
{
//switch(event.type)
//{
if(event.type = SDL_MOUSEBUTTONDOWN)
{
if (event.button.button == SDL_BUTTON_LEFT)
mousedown = true;
}
break;
if(event.type = SDL_MOUSEBUTTONUP)
{
if (event.button.button == SDL_BUTTON_LEFT)
mousedown = false;
}
break;
if(event.type = SDL_MOUSEMOTION)
{
if (mousedown) {
/* Change which part of bitmap to show */
bitmap_offset.x -= event.motion.xrel;
bitmap_offset.y -= event.motion.yrel;
/* Check rectangle values are valid */
if(bitmap_offset.x < 0)
bitmap_offset.x = 0;
if(bitmap_offset.y < 0)
bitmap_offset.y = 0;
if(bitmap_offset.x > max_x_origin)
bitmap_offset.x = max_x_origin;
if(bitmap_offset.y > max_y_origin)
bitmap_offset.y = max_y_origin;
/* update surface and show */
SDL_BlitSurface (bitmap, &bitmap_offset, screen, &offset);
SDL_Flip(screen);
}
}
break;
if( event.type == SDL_QUIT )
{
//Quit the program
running = false;
}
break;
//}
}
/* Don't hog the computer */
//SDL_Delay(100);
}
SDL_FreeSurface( bitmap );
SDL_Quit();
return 0;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement