QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Return Image...

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 ...

Reply
 
LinkBack Thread Tools
Old 06-28-2006, 09:08 AM   #1
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Question Return Image...

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];
}
and i use this here:

Code:
blitAlphaImageToScreen(0, 0, 25, 25, tank->GetSprite(0), 100, 100);
the prototype of that function is:

Code:
void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy);
but when i use the "tank->GetSprite(0)", the PSP freeze. And i need to reboot.

So, whats the wrong with this:

Code:
Image* TANK::GetSprite(int index)
{
	return sprite[index];
}
thanks in advance,

ShUr1k3n

Last edited by ShUr1k3n; 06-28-2006 at 10:53 AM..
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 10:37 AM   #2

100% Pure Awesome
 
Join Date: Jan 2006
Posts: 508
Trader Feedback: 0
Default

Well, you are calling GetImage and have the function set as GetSprite().
__________________

Ravine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 10:52 AM   #3
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Default

Quote:
Originally Posted by Ravine
Well, you are calling GetImage and have the function set as GetSprite().
No, thats not the problem. Thats an error when i type this thread.

Edited now...
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 10:56 AM   #4

100% Pure Awesome
 
Join Date: Jan 2006
Posts: 508
Trader Feedback: 0
Default

A few things, have you created the object tank from the TANK class by calling,
Code:
TANK tank;
If you have done that then try changing
Code:
blitAlphaImageToScreen(0,   0, 25, 25, tank->GetSprite(0), 100, 100);
to
Code:
blitAlphaImageToScreen(0,   0, 25, 25, tank.GetSprite(0), 100, 100);
Also, make sure you have created the tank object before making that call.
__________________

Ravine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 11:24 AM   #5
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Default

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];
}
But whats wrong???
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 11:31 AM   #6

100% Pure Awesome
 
Join Date: Jan 2006
Posts: 508
Trader Feedback: 0
Default

What type of variable is sprite?
__________________

Ravine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 11:32 AM   #7
 
Join Date: Jul 2005
Posts: 139
Trader Feedback: 0
Default

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
Garak is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 12:32 PM   #8
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Default

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");
}
Anything wrong with this?
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 12:34 PM   #9

100% Pure Awesome
 
Join Date: Jan 2006
Posts: 508
Trader Feedback: 0
Default

Did you, in your class definition delcare sprite as an array of Images, like so:
Image* sprite[4]; ?
__________________

Ravine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 12:37 PM   #10
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Default

Yap...

If in the "void main()" i use "AddSprite(0,path)".. . Works fine.
So why dont work good when i use in the "TANK::TANK" ???
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 01:28 PM   #11

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

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.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 01:34 PM   #12
 
ShUr1k3n's Avatar
 
Join Date: Apr 2006
Location: Coimbra, Portugal
Posts: 44
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
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.
But the other's variables are ok.

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");
}
i "print" all variables (x,y,...) and the numbers are ok. x = 100, y = 100...

The only problem is with the sprites, that return NULL...
ShUr1k3n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-28-2006, 04:29 PM   #13

100% Pure Awesome
 
Join Date: Jan 2006
Posts: 508
Trader Feedback: 0
Default

Are you trying to use the different sprites as different tanks? Like they are not all controlled by the same person or AI?
__________________

Ravine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
image , return

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 11:29 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us