Accessing the gfx.PutPixel from other scopes.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Kshitijthegreat
Posts: 3
Joined: August 23rd, 2021, 5:02 pm

Accessing the gfx.PutPixel from other scopes.

Post by Kshitijthegreat » August 23rd, 2021, 6:08 pm

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

loz_bl2_mario
Posts: 12
Joined: May 16th, 2020, 12:03 pm

Re: Accessing the gfx.PutPixel from other scopes.

Post by loz_bl2_mario » August 26th, 2021, 1:37 am

im assuming you didnt make a gfx pointer in your dudes draw method
Formerly know as goldengamesTM

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Accessing the gfx.PutPixel from other scopes.

Post by albinopapa » August 30th, 2021, 9:20 pm

the only classes I see in those files are position and inhibitions.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Accessing the gfx.PutPixel from other scopes.

Post by albinopapa » August 31st, 2021, 1:32 am

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 );
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply