Pixel (0,0) = width & height of all my sprites (FF FF FF green is width, orange is height)
Pixel (1,0) = # of rows
Pixel ((2,3,...n), 0)= # of columns in corresponding row.
Here's the problem. I'm using SDL for this program. It reads the width and the height perfectly using this function:
Uint32 Sprite::get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit
Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}
But when I try to get the number of columns, I'm wondering if this get_Pixel function is correct. Here's the relevant code I have thus far: (Keep in mind it truly pains me to show unfinished work, I'm sure there are MANY problems). I
Eventually I intend to turn Sprite into an abstract class, for testing purposes I'm hardcoding an image into it.
#include "SDL.h"
#include <vector>
#include <utility>
#include <iostream>
using namespace std;
#pragma once
class Sprite
{
private:
SDL_Surface *image;
Uint32 get_pixel32( SDL_Surface *surface, int x, int y );
void populateImages();
Uint32 getNumberOfPoses();
void getDimensions(Uint32* width, Uint32* height);
public:
Sprite();
~Sprite();
};
Sprite::Sprite()
{
image = SDL_LoadBMP("yellowdevil.bmp");
Uint32 colorkey = SDL_MapRGB(image->format,0xFF,0,0xFF);
SDL_SetColorKey(image,SDL_SRCCOLORKEY,colorkey);
populateImages();
}
Sprite::~Sprite(){}
void Sprite::populateImages()
{
Uint32 width;
Uint32 height;
Uint32 poses;
getDimensions(&width, &height);
poses = getNumberOfPoses();
}
void Sprite::getDimensions(Uint32* width, Uint32* height)
{
Uint32 x = get_pixel32(image,0,0);
x = x & 16777215;
*height = x & 4095;
*width = x>>12;
}
/**
*ERROR!
*/
Uint32 Sprite::getNumberOfPoses()
{
Uint32 x = get_pixel32(image,1,0);
x = x & 16777215;
return x;
}
Uint32 Sprite::get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit
Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}
Here's the image: (Thank you spriters resource, credit will be given to original artist)
Sabaku
The value I should get for (1,0): 000008
And the Value I'm getting for position (1,0): FFFF00
Once the game is written for PC, I plan on porting it to run on Android and Objective C. Should I just abandon SDL and move to OpenGL? What do you guys think?
This post has been edited by atraub: 06 February 2011 - 09:57 AM

New Topic/Question
Reply




MultiQuote





|