Jump to content
  • Advertisement
Sign in to follow this  
tonypr

Architecture question

This topic is 3178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, In my game; I have a Game class (very original) which contains different game scenes (other classes); let's say SceneA and SceneB Now; I wanted to add some kind of transition between SceneA and SceneB; so that when a user presses a key to move to the next scene, the old one fades to black first. My idea was to add a new class "Transition" to SceneA; that would have a "FadeOut" member. Then I simply have to call "FadeOut" from SceneA. The problem is that I have to detect when the fade out is over so my first guess was to create a function pointer in the transition class and call whatever is pointed to when the transition is over. So that; In my SceneA class; I'd have something like this: class Transition { ... void FadeOut(); void* OnFadeOutOver(void); } And in SceneA, I would have class SceneA { Transition t; void OnFadeOutOver(); } ... And somewhere in my SceneA code: t.OnFadeOutOver = this->OnFadeOutOver(); t.FadeOut(); But I guess this is wrong, since the linker gives me an unresolved external symbol error. Moreover, what I'm trying to achieve is maybe not the smartest way to do it. How would you proceed? Thanks! Tony

Share this post


Link to post
Share on other sites
Advertisement
Can we see some actual code, and the exact error message? (What you posted won't compile, for a number of reasons, so if you're getting to the link phase of the build I'm guessing your code is significantly different than what you've posted.)

Share this post


Link to post
Share on other sites
Hi Jyk,

I didn't want to post actual code so that I don't be rude copy/pasting dozen of code.

The class is very simple:

Transition.h
___________________________________

#pragma once
#if defined(WIN32)
#include <windows.h>
#endif
#include "Game.h"

class Transition
{
public:
Transition(void);
void FadeOut(); //start fade out
void FadeIn(); //NIY

void* OnFadeOutOver(void); //pointer to the function that will be called when fade out is over
void* OnFadeInOver(void);

bool Active; //determine if transition is currently on
float Length; //transition duration, in seconds

void Update();
void Draw();

~Transition(void);



private:
float time;


};




Transition.cpp
___________________________________

#include "Transition.h"

Transition::Transition(void)
{
Active = false;
Length = 0.5f; //500 miliseconds
}

Transition::~Transition(void)
{
}

void Transition::FadeOut()
{
//reset time
time = 0.0f;

//acitve!
Active = true;
}


void Transition::Draw()
{
if(Active)
{
//do some stuff
}
}

void Transition::Update()
{
if(Active)
{
time += Game::timer->ElapsedTime();

//detect if over
if(time > Length)
{
Active = false;
time = 0.0f;

//fading is over; call the end function
OnFadeOutOver();
}

}
}





_________________________________
Then, somewhere on an actual game scene that draw stuff, I have:

t.OnFadeOutOver = this->OnFadeOutOver();
t.FadeOut();





Error:
error LNK2001: unresolved external symbol "public: void * __thiscall Transition::OnFadeOutOver(void)" (?OnFadeOutOver@Transition@@QAEPAXXZ)

[Edited by - tonypr on October 11, 2009 2:56:25 PM]

Share this post


Link to post
Share on other sites
It's not rude to post code :) However, can you repost the code using [source][/source] tags? That'll make it much easier to read.

Share this post


Link to post
Share on other sites

void* OnFadeOutOver(void); //pointer to the function that will be called when fade out is over


This isn't a pointer-to-function. It's a function that returns pointer-to-void.

You meant:

void (*OnFadeOutOver)(void);


Though perhaps consider creating an interface or using something like boost::function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!