Some Level Editor problems!
Posted: Mon Feb 16, 2009 12:21 pm
Soo, I started working on the level editor for my little rpg, and I got one weird issue :O
The thing is on the clipping part of the tilesheet, not the clipping itself but what happens between it and the rendering of the tilesheet!
I do the clipping and load the function on the OnInit() part, then when I try using the clipTiles[] on the OnRender(), or OnLogic() that is inside my game loop, but suddenly all the values of clipTiles[] are set to NULL o.O
Here are some of the source codes:
-first the main function and game loop:
-Here is the source code of the tile part:
-Here is the OnInit() and OnRender()
Here is the thing... if I try printing the values of 'clipTile[5].x' on whatever part of OnInit() it will show right ... or if I try printing it inside my LoadTileSheet() it will also show the right numbers...
but if i try printing it on the OnRender() it will print '0' ... it does that in the transition between
I cant get to know 'why that???' ... I have already fried my neurons, can anyone help me solve this 'little' mistery?
P.S: And even if I try executing TileClips() in "OnRender()" and try printing the values after it, it will print "0" O.o
The thing is on the clipping part of the tilesheet, not the clipping itself but what happens between it and the rendering of the tilesheet!
I do the clipping and load the function on the OnInit() part, then when I try using the clipTiles[] on the OnRender(), or OnLogic() that is inside my game loop, but suddenly all the values of clipTiles[] are set to NULL o.O
Here are some of the source codes:
-first the main function and game loop:
Code: Select all
//main.cpp
#include "main.h"
//#include "Tile.h"
App::App()
{
Running = true;
screen = NULL;
layout = NULL;
}
int App::OnExecute()
{
if(OnInit() == false)
{
Running = false;
}
while(Running)
{
OnEvent();
OnLogic();
OnRender();
}
OnCleanup();
return 0;
}
int main(int argc, char *argv[])
{
App Execute;
return Execute.OnExecute();
}
-Here is the source code of the tile part:
Code: Select all
//Tile.cpp
#include "Tile.h"
#include "Globals.h"
#include "Surface.h"
Tile::Tile()
{
}
//Dont care about this now
SDL_Surface* Tile::LoadTilesheet(char *filename)
{
SDL_Surface *loaded = NULL;
SDL_Surface *optmized = NULL;
loaded = IMG_Load(filename);
for(int a = 0; a < 66; a++)
{
SurfaceBlit::DrawClips(tileCell[a].x, tileCell[a].y, loaded, optmized, &clipTiles[a]);
}
return optmized;
}
void Tile::TileClips()
{
int k = 0;
int j = 0;
int offX = 11;
int offY = 620;
for(int a = 0; a < 66; a++)
{
if(a == 22 || a == 44 || a == 66)
{
k = 0;
j++;
}
clipTiles[ a ].x = TILE_WIDTH * k;
clipTiles[ a ].y = TILE_HEIGHT * j;
clipTiles[ a ].w = TILE_WIDTH;
clipTiles[ a ].h = TILE_HEIGHT;
tileCell[ a ].x = offX + (TILE_WIDTH * k);
tileCell[ a ].y = offY + (TILE_HEIGHT * j);
//printf("%d %d \n", tileCell[a].x, tileCell[a].y);
k++;
}
}
Code: Select all
//OnInit.cpp
#include "main.h"
#include "Globals.h"
#include "Surface.h"
#include "Tile.h"
bool App::OnInit()
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
return false;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
if(screen == NULL)
{
return false;
}
SDL_WM_SetCaption("The Game - Level Editor", NULL);
Tile::TileClips();
layout = SurfaceBlit::OnLoad("assets/layout.png");
grid = SurfaceBlit::OnLoad("assets/grid.png");
tileSheet = Tile::LoadTilesheet("assets/tilesheet_2.png");
//tileSheet = SurfaceBlit::OnLoad("assets/tilesheet_2.png");
return true;
}
Code: Select all
//OnRender.cpp
#include "main.h"
#include "Surface.h"
#include "Tile.h"
void App::OnRender()
{
SurfaceBlit::DrawIMG(0, 0, layout, screen);
SurfaceBlit::DrawIMG(10, 618, grid, screen);
SurfaceBlit::DrawIMG(11, 620, tileSheet, screen);
//SurfaceBlit::DrawClips(clipTiles[1].x, clipTiles[2].y, tileSheet, screen, &clipTiles[3]);
SDL_Flip(screen);
}
but if i try printing it on the OnRender() it will print '0' ... it does that in the transition between
Code: Select all
OnInit();
while(Running)
{
.
.
.
OnRender();
}
P.S: And even if I try executing TileClips() in "OnRender()" and try printing the values after it, it will print "0" O.o