Jump to content

  • Log In with Google      Sign In   
  • Create Account

Toshio

Member Since 16 Sep 2011
Offline Last Active Nov 24 2012 03:55 PM

Topics I've Started

Weird artifacts and Frame Independent Movement

19 August 2012 - 04:42 AM

Greetings. I have two problems here.

First off, I'm using OpenGL with SDL.

The first problem are weird lines around the transparent PNG picture as shown in the screenshot:
Attached File  screenshot.png   7.4KB   40 downloads

This is the PNG picture:
Attached File  catanimate.png   1.1KB   40 downloads

How can I make the lines disappear?

The second problem is Frame Independent Movement. I got it all set up, and I thought it worked until a lot of things went happening at the same time. At some places entities move very fast, at some very slow, depending on what's rendering on screen and what logic is currently happening.

Here is some code:

this is main.cpp:
	 Uint32 delta = SDL_GetTicks();
	 SDL_Event event;
	 g.OnInit();
	 while(g.running)
	 {
			if(SDL_PollEvent(&event))
			{
				  g.OnEvent(&event);
	   	 }
	   	 g.OnLoop(SDL_GetTicks() - delta);
	   	 delta = SDL_GetTicks();
			g.OnRender();
	 }

and this is how the player, for example, moves:
	 x += xVel * (delta / 1000.0f);

Thank you for your help Posted Image

Weird artifacts and Frame Independent Movement

16 August 2012 - 07:42 AM

Greetings. I have two problems here.

First off, I'm using OpenGL with SDL.

The first problem are weird lines around the transparent PNG picture as shown in the screenshot:
Attached File  screenshot.png   7.4KB   43 downloads

This is the PNG picture:
Attached File  catanimate.png   1.1KB   40 downloads

How can I make the lines disappear?

The second problem is Frame Independent Movement. I got it all set up, and I thought it worked until a lot of things went happening at the same time. At some places entities move very fast, at some very slow, depending on what's rendering on screen and what logic is currently happening.

Here is some code:

this is main.cpp:
Uint32 delta = SDL_GetTicks();
	SDL_Event event;
	g.OnInit();
	while(g.running)
	{
		if(SDL_PollEvent(&event))
		{
			g.OnEvent(&event);
		}
		g.OnLoop(SDL_GetTicks() - delta);
		delta = SDL_GetTicks();
		g.OnRender();
	}

and this is how the player, for example, moves:
x += xVel * (delta / 1000.0f);

Thank you for your help Posted Image

Returning an element from an array

12 July 2012 - 04:20 PM

Hi there. I hope someone could help me solve this problem.

I suspect this is not the way to do it, but here's the code:

int tile[210][210];


int Map::getTile(int a, int b)
{
	return tile[a][b];
}

When I want to return the element in a different class, it returns 0.

Also, I can't make my tilemap (tile[a][b]) bigger than 212 * 212. The game crashes just after it launches.
Thanks for your help.

2D Tile Map Converter

22 April 2012 - 08:50 AM

I'd like to present you a tile map converter I made.

It's basically a Console Application in which you type in some data and the program converts a picture (Bitmap) you loaded to a level.map file.
In the level.map file you can find bunch numbers. Each of them represents a tile type you've set in the Console.

It is intended for beginners but can be used by advanced users too.

Download here: http://www.mediafire...stk7e1cep3o19u2

Video:
http://www.youtube.c...bed/LnhX8YuOgfc

A few screenshots:

Attached File  Capture.PNG   44.62KB   63 downloads

Attached File  Capture.PNG   6.97KB   59 downloads

Attached File  Capture3.PNG   59.16KB   66 downloads

Attached File  Capture2.png   100.83KB   73 downloads

Getting a PNG image from a resource file

30 March 2012 - 08:48 AM

Hello. I got this one problem I need to solve, and it's putting and getting a PNG image from a resource file.
I followed these two tutorials: http://content.gpwik..._Resource_Files and http://content.gpwik...sing_SDL_RWops.
Bitmaps work, but I can't get PNGs on the screen.

This is the code I thought would work for loading an image from a resource file:

SDL_Surface* CSurface::load_image(char *resource, char *File )
{
	int filesize = 0;
	char *buffer = GetBufferFromResource(resource, File, &filesize);
	SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
	SDL_Surface *loadedImage = IMG_LoadPNG_RW(rw);
	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;
	free(buffer);
	//If the image loaded
	if( loadedImage != NULL )
	{
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat( loadedImage );
		//Free the old image
		SDL_FreeSurface( loadedImage );
	}
	//Return the optimized image
	return optimizedImage;
}

... but it doesn't work.

I didn't touch the code from the tutorial where it creates a resource file, so that might be the problem.

PARTNERS