Jump to content

  • Log In with Google      Sign In   
  • Create Account


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!


Member Since 20 Jun 2012
Offline Last Active Jun 28 2012 10:05 AM

Topics I've Started

[SDL] SDL_Rect array

26 June 2012 - 06:05 AM

At the moment i'm trying implement plaforms in my 2d platformer. I want to store the platform data in an array of SDL_Rects. This is what I have:

In my header:
		SDL_Rect rPlatformArray[20];//maximum platforms in a level is 20 (for now)

This is how I change the array data:

if (type == 4){
  rPlatformArray[NumberOfPlatforms].x = x;
  rPlatformArray[NumberOfPlatforms].y = y;
  rPlatformArray[NumberOfPlatforms].h = h;
  rPlatformArray[NumberOfPlatforms].w = w;

And for rendering:

for (int i = 0; i <= NumberOfPlatforms;i++){

The problem seems to occur when I try to run the second code block.
There are no compile errors, only as soon as the game starts it crashes.

Can you help me?

[SDL] Timer problem

20 June 2012 - 06:26 AM

I'm currently trying to get familiar with SDL and C++, and i've been working on a little project involing a very basic game engine.
What I want to do at the moment is to implement a simple portal system. I have two portals, if my player steps on one of them he teleports to the other and vice versa. The problem is that, when using the portal, the collsion detection of the other portal interferese, and teleports the player infinitly from portal to portal. I wanted to fix this by adding a small delay before the portal is usable again, but somehow the function I wrote makes the game crash.
Here is the code i'm using:

To set the delay:
void Core::setPortalDelay(int time){
	Uint32 now;
	now = SDL_GetTicks();
while (now < time){
  PortalDelay = true;
if (now > time){
PortalDelay = false;
now = 0;

and to teleport the player:

if (CheckCol(PlayerLocation,rPortal1Loc) == true && PortalDelay == false){
  PlayerLocation.x = rPortal2Loc.x;
  PlayerLocation.y = rPortal2Loc.y;
if (CheckCol(PlayerLocation,rPortal2Loc) == true && PortalDelay == false){
  PlayerLocation.x = rPortal1Loc.x;
  PlayerLocation.y = rPortal1Loc.y;