![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Return Image... within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hey guys, how can i return a image from a Class? for example: i have this code: Code: Image* TANK::GetSprite(int ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
|
Hey guys,
how can i return a image from a Class? for example: i have this code: Code:
Image* TANK::GetSprite(int index)
{
return sprite[index];
}
Code:
blitAlphaImageToScreen(0, 0, 25, 25, tank->GetSprite(0), 100, 100); Code:
void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy); So, whats the wrong with this: Code:
Image* TANK::GetSprite(int index)
{
return sprite[index];
}
ShUr1k3n Last edited by ShUr1k3n; 06-28-2006 at 10:53 AM.. |
|
|
|
|
|
|
#4 |
![]() ![]() 100% Pure Awesome
|
A few things, have you created the object tank from the TANK class by calling,
Code:
TANK tank; Code:
blitAlphaImageToScreen(0, 0, 25, 25, tank->GetSprite(0), 100, 100); Code:
blitAlphaImageToScreen(0, 0, 25, 25, tank.GetSprite(0), 100, 100); |
|
|
|
|
|
#5 |
|
No, the problem isnt that too.
Because if u use tank->GetX() or tank->SetX(). Works fine. I think that the problem is with this code: Code:
Image* TANK::GetSprite(int index)
{
return sprite[index];
}
|
|
|
|
|
|
|
#7 |
![]() |
What you have so far should be fine.
When you call tank->GetSprite(0), you are returning a pointer to an image. It would seem index 0 does not contain a pointer to a valid image. Do this: // Ensure your tank class initilizes all pointers in the sprite array to 0. Image *i1 = tank->GetSprite(0); if (i1) { blitAlphaImageToScreen(.. .); } else { printf("Null pointer returned"); } Also, verify that you have actually stored an Image at index 0 in your sprite array. Garak |
|
|
|
|
|
#8 |
|
Garak i use ur method. And i got the "Null pointer return".
But in my class i have this: Code:
TANK::TANK()
{
strcpy(type,"Tank");
maxEnergy = 10;
energy = 10;
shotSpeed = 1;
direction = 1;
x = 10;
y = 10;
sprite[0] = loadImage("Data/Tanks/Tank1.png");
sprite[1] = loadImage("Data/Tanks/Tank2.png");
sprite[2] = loadImage("Data/Tanks/Tank3.png");
sprite[3] = loadImage("Data/Tanks/Tank4.png");
}
|
|
|
|
|
|
|
#11 |
![]() ![]() ...in a dream...
|
Well, I dont know C++ as the next guy, but I do undrstand a class and function's 'names' if you will, should not be the same, case-sensitive.
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#12 | |
|
Quote:
Look: Code:
TANK::TANK()
{
strcpy(type,"Tank");
maxEnergy = 10;
energy = 10;
shotSpeed = 1;
direction = 1;
x = 100;
y = 100;
sprite[0] = loadImage("Data/Tanks/Tank1.png");
sprite[1] = loadImage("Data/Tanks/Tank2.png");
sprite[2] = loadImage("Data/Tanks/Tank3.png");
sprite[3] = loadImage("Data/Tanks/Tank4.png");
}
The only problem is with the sprites, that return NULL...
|
||
|
|
|
![]() |
| Tags |
| image , return |
| Thread Tools | |
|
|