Sign in to follow this  
dairylee

PTK drawing issue

Recommended Posts

I'm trying to learn how to use PTK but I can't find any resources anyway so I'm trying to learn by just coding something. I've came across a stumbling block early on though. For some reason 'theSquare' is not drawing to the screen but 'evilSquare' draws fine. main.cpp
#include "ptk.h"
#include "COurSquare.h"

KWindow *ourWindow = NULL ;


//Create our Square
COurSquare *theSquare = new COurSquare;


int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow )
{
	//Create the game window
	ourWindow = KPTK::createKWindow(K_OPENGL);					// Init Window
	ourWindow->createGameWindow(710,410,32,true,"Squares");		// Create Window
	
	//Setup background image
	KGraphic *ourBg = NULL ;
	ourBg = KPTK::createKGraphic("bg.png");

	//Define and Allocate space for the Squares
	KGraphic *evilSquare = NULL ;

	//Initialize the Squares
	evilSquare = KPTK::createKGraphic("evilsquare.jpg") ;


	//Font
	KTrueText *myFont ;
	myFont = new KTrueText( KMiscTools::makeFilePath( "x:/coding/squares/squares/images/font.ttf") ) ;
	

	//MAIN GAME LOOP
	while(ourWindow->isQuit() == false)
	{
		ourBg->blitRect( 0,0,710,410,1,1,1,1.0f);		

		theSquare->move();

		ourWindow->setDefaultWorldView();

		theSquare->draw();
		evilSquare->blitRect(0,0,30,30,250,250);

		myFont->drawStringFromRight( "lee.thomas.taylor@gmail.com" ,709,390,0) ;
		myFont->setColor( 0,1,0,0.3f ) ;
		
		ourWindow->flipBackBuffer();
		ourWindow->processEvents();
	};


	//CLEANUP
	delete ourWindow;
	ourWindow = NULL;
	delete theSquare;

	if ( evilSquare!= NULL )
	{
		delete evilSquare ;
		evilSquare = NULL ;
	}



	return 0 ;
}

COurSquare.h
#pragma once
#include "ptk.h"

class COurSquare
{
	private:
		KGraphic* ourSquare;
		short xPos;
		short yPos;

	public:
		COurSquare();
		~COurSquare();

		void initialise();
		void release();

		void draw();
		void move();

		short getXPos();
		short getYPos();
};

COurSquare.cpp
#include "COurSquare.h"

COurSquare::COurSquare()
{
	ourSquare = NULL ;
	ourSquare = KPTK::createKGraphic("square.png") ;	

	xPos = 0;
	yPos = 0;
};

COurSquare::~COurSquare()
{
	release();
};

void COurSquare::initialise()
{
	
};

void COurSquare::release()
{
	if ( ourSquare!= NULL )
	{
		delete ourSquare ;
		ourSquare = NULL ;
	}
};

void COurSquare::draw()
{
	ourSquare->blitRect(0,0,40,40,xPos,yPos);
};

void COurSquare::move()
{
	xPos = KInput::getMouseX( ) ;
	yPos = KInput::getMouseY( ) ;
};

I'm sure there is an easy solution to this so hopefully one of you guys can help me with this. Thanks in advance, Lee.

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