Alright, So I thought to myself Boy wouldn't it be great if all of the objects stored a pointer to the sprite that I'd like to have them render with? Sounds fantastic to me!
Thus I made this little file looking something like this
//Spritelist.h
#pragma once
#include "Sprite.h"
namespace SpriteList
{
static Sprite Player1("Rainbow.bmp",64,64,4,4);
}
And then Within the Object class I have there is a Sprite pointer pointing to said static variable. Wow great!
But then onto my Render Method Something appears to be askew!?
//Within some direct3d file
void Direct3D::render_frame(vector<Object> *Objects)
{
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,0100),1.0f,0);
d3ddev->BeginScene();
d3dspt->Begin(NULL);
for(vector<Object>::iterator index = Objects->begin();index != Objects->end();index++)
{
//does not pass, however if the line fallowing labeled "WiggityWack"it passes then the second time this //function goes by (I assume) it does pass
if(index->sprite==&Player1)
{
index->sprite->frameStore++;
}
//"WiggityWack" index->sprite = &Player1; <- also if the equivilent of this line is //place in the code that calls this render function the top if statement still willl not pass.
//does pass
if(index->sprite->cols==Player1.cols)
{
index->sprite->frameStore++;
}
//index->sprite=&Player1;
//does not render anything
DrawSprite(index->sprite,1, 64, 64 , 1.0f);
//Does render something! Wow thats great!
DrawSprite(&Player1,1, 64, 64 , 1.0f);
}
d3dspt->End();
d3ddev->EndScene();
d3ddev->Present(NULL,NULL,NULL,NULL);
}
I've done a lot of random tests and I've cut down the problem to the objects within the vector's sprite member simply isn't pointing to that static Sprite called Player1. Static variables have been something I've tried to avoid as I've heard people like to avoid them, so now that I am using one I'm wandering if perhaps I've misinterpretted their use and that's related to why this does not work. Would anyone be able to clarify on this?
I'll post my Object class just in case you see anything stupid there that i totally passed, but i believe there is nothing wrong here.
//Object.h
struct Object
{
public:
//constructor and deconstructodon Awww yeah!
Object(/*HWND *hwnd,*/Sprite *_sprite ,int _x, int _y);
~Object();
// I forget what these are called, uuuuh like... variables inside a class, it's somethin stupid.
//HWND hwnd;
Sprite * sprite;
unsigned int frame;
int x, y;
//methods
void update(/*inputdata*/);
};
//Object.cpp
Object::Object(Sprite *_sprite ,int _x, int _y) :sprite(_sprite), x(_x), y(_y),frame(0)
{
}
Object::~Object()
{
}
void Object::update(/*inputdata*/)
{
}