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.
Accessing the gfx.PutPixel from other scopes.
-
- Posts: 3
- Joined: August 23rd, 2021, 5:02 pm
-
- Posts: 12
- Joined: May 16th, 2020, 12:03 pm
Re: Accessing the gfx.PutPixel from other scopes.
im assuming you didnt make a gfx pointer in your dudes draw method
Formerly know as goldengamesTM
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Accessing the gfx.PutPixel from other scopes.
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
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Accessing the gfx.PutPixel from other scopes.
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.
In Game::ComposeFrame(), you'd call like:
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 );
}
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