• 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
ThePointingMan

A little confusion with rendering a sprite!

5 posts in this topic

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*/)
{
}

 

0

Share this post


Link to post
Share on other sites
Static in this context means one copy per translation unit. Every cpp file will have its own copy of that sprite.

Assuming you want to use a global (and you should revisit that decision at some point), declare it as extern in the header and define it in one cpp file only.
0

Share this post


Link to post
Share on other sites

I am aware that keeping this in global space is to be avoided, I'm just not sure how one would go about doing this without doing so. I would like to be able to have something like this for the constructor of the child class of an object

//PlayerSpt Sprite("File",blabla variables n crap)
//Player class, child of Object class
Player(x,y):Object(&Player,x,y)

But it needs to be accesible to my method that loads in all of the graphics. Does anyone have some advice on how I might do this, is there some other method people would advise for doing this or am I just dreaming and will have to use one of the other idea's I've come up with such as using an intager instead of a sprite pointer and making the sprite only accesible to the d3ddevise and using the intager to pick which sprite is being used.

0

Share this post


Link to post
Share on other sites

You could do this plenty of ways but your idea about using an integer instead of a pointer is sensible.  I'd suggest looking into that more. Using an integer or a handle or really any mechanism for keeping a 'name' to your referenced object would be better than keeping a pointer directly all the time.  And as you've already guessed you can start limiting how much of your code needs to know specifics like what a Sprite is.

0

Share this post


Link to post
Share on other sites

Beautiful! I had an idea of something similar to that but there where a few things that just... I dunno I felt like they would be messy. What you've written up there looks very clean and usable. There are a few keywords I've never seen before, but I'm sure I'll be able to look those up for the most part. I'll let you know if I'm having any troubles in that regard.

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