Page 1 of 1

Accessing the gfx.PutPixel from other scopes.

Posted: August 23rd, 2021, 6:08 pm
by Kshitijthegreat
So I am not a beginner but I also wouldn't call myself a chili-level PROgrammer.
I have made a class for the dude sprite in the tutorial 8 poopoo eater game. I have made a function inside the class to draw the face. But the gfx is not defined in that scope. How do I fix it?
I have included only the Game.h and Game.cpp files because thats only what i changed, other files are as it is.
Game.h
(2.23 KiB) Downloaded 188 times
Game.cpp
(3.27 KiB) Downloaded 191 times

Re: Accessing the gfx.PutPixel from other scopes.

Posted: August 26th, 2021, 1:37 am
by loz_bl2_mario
im assuming you didnt make a gfx pointer in your dudes draw method

Re: Accessing the gfx.PutPixel from other scopes.

Posted: August 30th, 2021, 9:20 pm
by albinopapa
the only classes I see in those files are position and inhibitions.

Re: Accessing the gfx.PutPixel from other scopes.

Posted: August 31st, 2021, 1:32 am
by albinopapa
Ultimately, there are a few steps to achieve what you want.

First, you must #include "Graphics.h" at the top of the header ( .h ) file you want to use the Graphics class. Put this line after #pragma once.

Second, in the declaration of the Draw function you must pass the Graphics object by reference or by pointer. I'm only going to show pass by reference.

Code: Select all

void Draw( Graphics& gfx ){
     gfx.DrawBox( x, y, size, size, color );
}
In Game::ComposeFrame(), you'd call like:

Code: Select all

void Game::ComposeFrame(){
     dude.Draw( gfx );
}