• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AussieSpoon

Set class (member) pointer to a existing class (to allow editing)

5 posts in this topic

Hello,

 

I have two classes. I am trying to get the 2nd class to have a member pointer that points to an instance of the first class (Giving the 2nd class the ability to edit an instance of the first class) . But I am unsure how to set this up (when I use it the values I try to edit don't change) 

 

Here is what I have tried:

class A
{
 m_MemberA;
};

class B
{
 void SetMemberPointer(*A _a)  {m_MemberB = _a;}
 A* m_MemberB
};

void main()
{
 A Class1;
 B Class2;

 Class2.SetMemberPointer(&Class1);

}

 

Can some one explain why this doesn't work/help with a solution?

 

Thanks 

Edited by AussieSpoon
0

Share this post


Link to post
Share on other sites

when I use it the values I try to edit don't change

Post the actual code you are using. What you have shouldn't even compile, which means it's very hard to determine why the runtime behavior you are describing would occur.
0

Share this post


Link to post
Share on other sites

Class 1 (.h):

 

struct DrawArea
{
	float  left, right, top, bottom; 
};

class Texture
{
public:
	Texture(void);
	Texture(IDirect3DTexture9 &_Texture);
	Texture(IDirect3DTexture9 &_Texture, float  _startX, float  _startY, float  _endX, float  _endY);
	~Texture(void);

	IDirect3DTexture9* GetDXTexture() {return m_Texture;}
	DrawArea GetDrawArea()			  {return m_DrawArea;}
	//u = x, v = y co-ordinate
	float GetTextureUMin();	//the x start (left)
	float GetTextureUMax();	//the x end (right)
	float GetTextureVMin();	//the y start (top)
	float GetTextureVMax();	//the y end (bottom)

	uINT GetWidth();		//will return the width of the texture at level 0
	uINT GetWidth(uINT _level);
	uINT GetHeight();		//will return the width of the texture at level 0
	uINT GetHeight(uINT _level);

	void SetToTexture(Texture &_texture);
	void SetToTexture(Texture *_texture);
	void SetDXTexture(IDirect3DTexture9 &_Texture);
	void SetDXTexture(IDirect3DTexture9 *_Texture);
	void SetDXTexture(IDirect3DTexture9 &_Texture, float  _startX, float  _startY, float  _endX, float  _endY);
	void SetDXTexture(IDirect3DTexture9 *_Texture, float  _startX, float  _startY, float  _endX, float  _endY);
	void SetDrawArea(float  _startX, float  _startY, float  _endX, float  _endY);


private:

	IDirect3DTexture9* m_Texture;//The DirectX texture
	DrawArea m_DrawArea;
};

 

 

Class 2 (.h):

 

class Animation
{
public:
	Animation(void);
	Animation(Texture* _Texture, float StartX, float StartY, short Rows, short Columns, float FrameWidth, float FrameHeight, short Speed);
	~Animation(void);

	void Update();

private:

	Texture* m_Texture;//????!?!!?
	float m_StartX;
	float m_StartY;
	short m_Rows;
	short m_Columns;
	short m_CurrentFrame;
	short m_CurrentFrameX;
	short m_CurrentFrameY;
	float m_FrameWidth;
	float m_FrameHeight;
	short m_Time;
	
	//short m_Counter (Might be better to make this global (To only have instance of it instead of 1 per animation)
};

 

Class 2 (.cpp):

 

Animation::Animation(Texture* _Texture, float StartX, float StartY, short Rows, short Columns, float FrameWidth, float FrameHeight, short Speed)
{
	m_Texture = _Texture;

	m_StartX = StartX;
	m_StartY = StartY;
	m_Rows = Rows;
	m_Columns = Columns;
	m_FrameWidth = FrameWidth;
	m_FrameHeight = FrameHeight;
	m_Time = Speed;

	m_CurrentFrame = 0, m_CurrentFrameX = 0, m_CurrentFrameY = 0;
}

 

Creating/using the variables:

 

Animation *TestAnimation;
............

TestAnimation = new Animation(&TestSprite1->GetTexture(), 0, 0, 4, 1, 64, 64, 1);
TestSprite1->SetAnimation(TestAnimation);
0

Share this post


Link to post
Share on other sites
1) What is TestSprite1? Is it a Texture? It doesn't look like it. In particular what does the GetTexture() function look like?
2) You never actually try to make any changes so of course you don't see any effects.
3) It's easier to do problem solving in these kinds of cases if you can break down the problem to a minimal, but complete, compilable example. To be minimal it shouldn't include anything that isn't relevant to the problem (ex: member functions that are never called) but to be complete it should still show all the bits that show the core of what you are attempting to do.
2

Share this post


Link to post
Share on other sites

In particular what does the GetTexture() function look like?

 

Oh man, this was my problem. I was returning the texture as an object, but I have a different function for returning it as a pointer. Since the animation take a pointer I needed to return it as a pointer.

 

Thanks heaps for pointing that out, you are a legend.  It works fine now. 

0

Share this post


Link to post
Share on other sites

//short m_Counter (Might be better to make this global (To only have instance of it instead of 1 per animation)


Unrelated, but in regards to this, I'd suggest making it a static variable in the class, rather than having it clutter the global namespace, or be visible to classes that shouldn't see it.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0