Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


albertino

Member Since 16 Apr 2012
Offline Last Active Oct 06 2014 11:24 PM

Posts I've Made

In Topic: need help SDL EVENTS!

23 April 2012 - 04:32 AM

i am not very good at handling event too but if i can answer what you are trying to create it is a button so if your function it is insert in a pollevent chain will work but i see something strange thing in it if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
box.x box.y box.w box.h are the coordinates of your rectangle but where you define in the function?
should be somewhere
SDL_Rect box
box.x=......
box.y=....
box.w=....
box.h=.....

alternatevly (never tryied you might try to import from somewhereelse very bad in my opinion)
void Button::handle_events(int box.x, int box.y, int box.w, int box.h)

hope helps
regards

In Topic: SDL help with my program

23 April 2012 - 04:07 AM

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

#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;
}

PARTNERS