Stratos: Punto de Encuentro de Desarrolladores

¡Bienvenido a Stratos!

Acceder

Foros





Blitting map on seperate SDL_Surface and not CRM32Pro.screen

Iniciado por Blackuknown, 21 de Abril de 2008, 05:34:08 PM

« anterior - próximo »

Blackuknown

Greetings,

Right now i have a tilemap made with the MS Scrolling Engine. I totally love it. However if i use MoveLayer i have to relocate all the sprites on their corresponding positions each time i use it. This of course will drop my framerate alot if i have some creatures and npcs walking around. So what i really would like to do is instead of moving the layers moving the player around and making some sort of camera that follows him.

For this to be done i need to have the map on a seperate surface which i then will be able to clip and blit to CRM32Pro.screen. I can't get this to work. Whenever i give the map a render target different then CRM32Pro.screen i get nothing but a blackscreen.

The map does work on CRM32Pro.screen.

Here is my map.cpp:


#include "Map.h"

Map::Map(SDL_Surface *target){
  this->target = target;

  SE = new cMSSE;
  SE->Init("Map");
  SE->SetRenderTarget(target);

  tileset = new CRM32Pro_CTile;
  //tileset->Create("tiles.bmp","test");
  tileset->Load(GFX_RESOURCE, "Tileset");
  tileset->SetTileSet(1, 32, 32);

  mapBase = new cMSSE_MapBase(100,100);
  mapBase->SetMapBaseValue(-1,-1,2); // Fill all map with value 1
  mapBase->SetTileSizeX(32);
  mapBase->SetTileSizeY(32);
  if(mapBase->CheckMap() == 0)
  ILogSystem.Msg(LOG_NORMAL," - ManualLoad() has found problems checking the map on layer 0\n");
 
// Assign the map and tileset to layer '0'
   SE->SetLayerMapData(0, mapBase);
   SE->SetLayerTileset(0, tileset);
   // Set the status: execution and autospeed
SE->SetLayerStatus(0,SE_LAYERSTATUS_EXECUTE_SPEED);

// -Layer '1' initialization-
   layer1 = new cMSSE_MapBase(100, 100);
   layer1->SetTileSizeX(32);
   layer1->SetTileSizeY(32);
for(int i = 0; i < 100; i++){
for(int j = 0; j < 100; j++){
layer1->iTilemap[i][j] = 6;
}
}

layer1->iTilemap[50][40] = 20;

   layer1->CheckMap();
 
   SE->SetLayerMapData(1, layer1);
   SE->SetLayerTileset(1, tileset);
   SE->SetLayerStatus(1, SE_LAYERSTATUS_EXECUTE_SPEED);

SE->SetLayerPosition(1,SE_LAYERPOSITION_MIDDLE, SE_LAYERPOSITION_MIDDLE);

SDL_Rect offset;

offset.x = 512 - 10*32;
offset.y = 384 - 8*32;
offset.h = 16*32;
offset.w = 20*32;

SE->SetViewport(&offset);
}

void Map::init(){
 
}

void Map::update(){
SE->Update();
}

void Map::moveLayer(int layer, int x, int y){
SE->MoveLayer(layer, x, y);
}


Here are some relevant pieces of code from my Controller.cpp:


//I dont know any other way to initiate an SDL_Surface if there is one //please tell me.
mapSurface = IImage->Load(GFX_RESOURCE, "background");

map = new Map(mapSurface);

//Game loop
void Controller::Run(){
while(!quit){
calculateFrames();
checkInput();
movePlayer();
//AI routine
drawGame();
updateWindow();
clearMemory();
}

CRM32Pro.Quit();
}

//the drawGame method
void Controller::drawGame(){
       //No clipping yet. Calculated camera clipping should happen here.
SDL_BlitSurface(mapSurface,NULL,CRM32Pro.screen,NULL);
map->update();

SDL_BlitSurface(fps,NULL,CRM32Pro.screen,NULL);
player->draw();
}


What am i doing wrong? or what is missing?

Greetings,

Blackunknown(made a typo while registering)

TheAzazel

In order to help you better, please, send me your source code (remove all non-necessary stuff) and I will debug it for yourself.

In the meantime, another way to create a surface is to use the normal methods of SDL(SDL_LoadBMP(), SDL_CreateRGBSurface(),etc..).

Cheers!






Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.