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

Sprite won't change position

5 posts in this topic

When I run the program, all the sprites are in the correct position, however when I press a button to move the paddle it stays in the same place. I know that the input is working because I tested it with system beeps, and I know that the position of the sprite is changing because I had the x and y coordinates sent to a file as I pressed the button. Im not sure why the texture stays in the same place. Here's the code:

 

I also uploaded the entire project incase anyone wanted a closer look

 

 

//WinMain.cpp

Object Ball;
	Ball.setTexture( g.LoadTexture( "Resources/Ball.png" ) );
	Ball.setImageInfo( "Resources/Ball.png" );
	Ball.setPosition( ( ( WindowWidth / 2 ) - Ball.getImageInfo().Width ), ( ( WindowHeight / 2 ) - Ball.getImageInfo().Height ) );

	Object LeftPaddle;
	LeftPaddle.setTexture( g.LoadTexture( "Resources/LeftPaddle.png" ) );
	LeftPaddle.setImageInfo( "Resources/LeftPaddle.png" );
	LeftPaddle.setPosition( 0, ( ( WindowHeight / 2 ) - LeftPaddle.getImageInfo().Height ) );

	Object RightPaddle;
	RightPaddle.setTexture( g.LoadTexture( "Resources/RightPaddle.png" ) );
	RightPaddle.setImageInfo( "Resources/RightPaddle.png " );
	RightPaddle.setPosition( ( WindowWidth - RightPaddle.getImageInfo().Width ), ( WindowHeight / 2 ) - RightPaddle.getImageInfo().Height );

	g.getObjectManager().AddObject( Ball );
	g.getObjectManager().AddObject( LeftPaddle );
	g.getObjectManager().AddObject( RightPaddle );

	Input i;

	i.InitInput( window );

	while ( GameOver != true )
	{
		if ( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) )
		{
			TranslateMessage( &message );
			DispatchMessage( &message );
		}

		i.RefreshInput();

		if ( i.KeyPressed( DIK_ESCAPE ) )
		{
			GameOver = true;
		}

		if ( i.KeyPressed( DIK_UP ) )
		{
			LeftPaddle.Move( 0.0f, -0.5f );
		}

		if ( i.KeyPressed( DIK_DOWN ) )
		{
			LeftPaddle.Move( 0.0f, 0.5f );
		}

		g.UpdateGraphics();
	}

 

 

//ObjectManager.h

#ifndef OBJECTMANAGER_H
#define OBJECTMANAGER_H

#include "Object.h"
#include <list>
#include <d3dx9.h>

class ObjectManager
{

public:

	//ObjectManager() {}
	//~ObjectManager() {}

	void AddObject( Object &object );

	void ReleaseTextures();

	void UpdateObjectManager( LPD3DXSPRITE &sprite );

private:

	std::list<Object>           Objects;
	std::list<Object>::iterator Iter;
};

#endif  OBJECTMANAGER_H

 

 


//ObjectManager.cpp

#include "ObjectManager.h"
#include "Globals.h"

void ObjectManager::AddObject( Object &object )
{
	Objects.push_back( object );
}

void ObjectManager::ReleaseTextures()
{
	Iter = Objects.begin();

	while ( Iter != Objects.end() )
	{
		RELEASE( Iter -> getTexture() );

		Iter++;
	}
}

void ObjectManager::UpdateObjectManager( LPD3DXSPRITE &sprite )
{
	Iter = Objects.begin();

	while ( Iter != Objects.end() )
	{
		sprite -> Draw( Iter -> getTexture(), NULL, NULL, &Iter -> getPosition(), White );

		Iter++;
	}
}

 

 

 

 

//Graphics.h

#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "DxManager.h"
#include "ObjectManager.h"
#include <d3dx9.h>
#include <string>

class Graphics
{

public:

	bool InitGraphics( HWND &window );

	void StartScene();
	void Render();
	void EndScene();

	void UpdateGraphics();

	void ReleaseTextures();

	LPDIRECT3DTEXTURE9 LoadTexture( std::string file );

	DxManager     &getD3DManager()    { return this -> D3DManager; }
	ObjectManager &getObjectManager() { return this -> ObjManager; }
	HWND          &getWindow()        { return this -> Window; }

private:

	HWND Window;

	DxManager     D3DManager;
	ObjectManager ObjManager;
};

#endif  GRAPHICS_H

 

 

 

//Graphics.cpp

#include "Graphics.h"
#include "Globals.h"

bool Graphics::InitGraphics( HWND &window )
{
	this -> Window = window;

	if( !D3DManager.InitD3D( window ) )
	{
		GameOver = true;
		MessageBox( window, "Error initializing DirectX9", "Error", MB_OK );
		return false;
	}

	return true;
}

void Graphics::StartScene()
{
	D3DManager.getDirect3DDevice() -> Clear( 0, NULL, D3DCLEAR_TARGET, Black, 0.0f, 0 );

	D3DManager.getDirect3DDevice() -> BeginScene();
	D3DManager.getSpriteObject()   -> Begin( D3DXSPRITE_ALPHABLEND );
}

void Graphics::Render()
{
	ObjManager.UpdateObjectManager( D3DManager.getSpriteObject() );
}

void Graphics::EndScene()
{
	D3DManager.getSpriteObject()   -> End();
	D3DManager.getDirect3DDevice() -> EndScene();

	D3DManager.getDirect3DDevice() -> Present( NULL, NULL, NULL, NULL );
}

void Graphics::UpdateGraphics()
{
	StartScene();
	Render();
	EndScene();
}

void Graphics::ReleaseTextures()
{
	ObjManager.ReleaseTextures();
}

LPDIRECT3DTEXTURE9 Graphics::LoadTexture( std::string file )
{
	LPDIRECT3DTEXTURE9 texture = NULL;

	D3DXIMAGE_INFO info;

	D3DXGetImageInfoFromFile( file.c_str(), &info );

	HRESULT hr = D3DXCreateTextureFromFileEx( 
		D3DManager.getDirect3DDevice(),
		file.c_str(),
		info.Width, info.Height,
		1,
		D3DPOOL_DEFAULT,
		D3DFMT_UNKNOWN,
		D3DPOOL_DEFAULT,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		Transparent,
		&info,
		NULL,
		&texture );

	return texture;
}
Edited by Cryptiik
0

Share this post


Link to post
Share on other sites

I don't think that's the problem or else the textures wouldn't render at all when the program starts? The textures render fine, they just don't move or change positions after the initial setPosition(). When I try to move them with input, the texture stays in place despite the fact that it's D3DXVECTOR3 coordinates are changing

0

Share this post


Link to post
Share on other sites

It's because you're updating the position of one copy of your paddle, and drawing another.

Doing a push_back() in your ObjectManager makes a copy of your LeftPaddle object.

You should either change the list to be a list of (smart) pointers, or somehow retrieve a reference/pointer to the paddle object from the ObjectManager and update it when input occurs.

2

Share this post


Link to post
Share on other sites

Objects.push_back( object );

 

std::vector::push_back() adds a copy of 'object' at the end of the vector. LeftPaddle in WinMain is no longer the same object as stored in Objects[].

 

std::list<Object*> Objects;

 

...should work.

1

Share this post


Link to post
Share on other sites

Thanks alot guys, that solved the problem :) Sorry if I keep coming back on here so often when I have a problem, I'm just trying to learn to make games again. It's been a while and I'm still a bit rusty unsure.png

1

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