Image Movement Help

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Image Movement Help

Post by ^L^ »

Code: Select all

	int x=120;
	int y=60;

int main() {
	SceCtrlData pad;
	char buffer[200];
	Image* ourImage;
	pspDebugScreenInit();
	SetupCallbacks();
	initGraphics();

	sprintf(buffer, "ourImage.png");
	ourImage = loadImage(buffer);
	sceDisplayWaitVblankStart();

while(1){
	blitAlphaImageToScreen(0, 0, 32, 32, ourImage, x, y);
	if(pad.Buttons & PSP_CTRL_LEFT) {
		x-=1;
	}
	if(pad.Buttons & PSP_CTRL_RIGHT) {
		x+=1;
	}
	if(pad.Buttons & PSP_CTRL_UP) {
		y-=1;
	}
	if(pad.Buttons & PSP_CTRL_DOWN) {
		y+=1;
	}
}
	


	flipScreen();

	sceKernelSleepThread();
	return 0;
}
Why won't this work?
What can I do to fix it so that my image actually moves around whenever I press the buttons?
I've tried like, 50 different combinations and positions of stuff and I couldn't get it to work.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

place this after you open your while loop:

Code: Select all

sceCtrlPeekBufferPositive(&pad, 1);
Image
Upgrade your PSP
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Pirata Nervo wrote:place this after you open your while loop:

Code: Select all

sceCtrlPeekBufferPositive(&pad, 1);
Oh, yeah! I can't believe I forgot that!
I don't think that's all that I need to make this work though.
hibbyware
Posts: 78
Joined: Wed Mar 28, 2007 10:29 am

Post by hibbyware »

flipScreen(); will never be reached where you have placed it,

Also before your next question comes you need to also clearscreen every loop as without it your image will leave a smudgy trail,
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Code: Select all

	int x=120;
	int y=60;

int main() {
	SceCtrlData pad;
	char buffer[200];
	Image* ourImage;
	pspDebugScreenInit();
	SetupCallbacks();
	initGraphics();

	sprintf(buffer, "ourImage.png");
	ourImage = loadImage(buffer);
	sceDisplayWaitVblankStart();

while(1){
	sceCtrlPeekBufferPositive(&pad, 1);
	blitAlphaImageToScreen(0, 0, 32, 32, ourImage, x, y);
	if(pad.Buttons & PSP_CTRL_LEFT) {
		x-=1;
	}
	if(pad.Buttons & PSP_CTRL_RIGHT) {
		x+=1;
	}
	if(pad.Buttons & PSP_CTRL_UP) {
		y-=1;
	}
	if(pad.Buttons & PSP_CTRL_DOWN) {
		y+=1;
	}
	pspDebugScreenClear();
	flipScreen();
}

	sceKernelSleepThread();
	return 0;
}
So, this is what I have now.
It's not working though. how would I fix it?
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

you are clearing the screen with the debug. you can't have debug + GU working at the same time.
Image
Upgrade your PSP
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You also need to clear the screen BEFORE you write to it, not before you flip. That simply would erase everything you'd done. :D
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

So, what would I need to do instead pspDebugScreenClear(); ?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You seem to be using graphics.c. Look through it - there's lots of stuff in there.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Okay, wow. I love you guys!
Okay, I checked the graphics.c and I saw a function called screenClear(color color); and I tried that and it didn't work. So I was like, oh yeah, I need to have a color in it. So I put 0x00 and it worked!
I'm soooo happy!
I've been trying to get this to work for at least a year and a half! Thanks soo much!
BTW, psp-programming is an awful forum to go onto for questions.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

a year and a half? o.O

by the way, I recommend you to use unsigned 32 colors.
Remember the PSP little endian so the colors are in a inverted order:
0xAABBGGRR
alpha, blue, green, red
Image
Upgrade your PSP
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

And be sure to check for warnings in the cygwin or command prompt. it could help lead to a solution.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Yeah, I was just now about to change that to 0xFFFFFFFF
I was just using it as an example.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

For the time being, I want the background of the screen to be white.
What's the function for this?
I forgot. Heehee.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Nvm. I got it!



Oh.. um. triple post? Sorry.
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

Please read the rules before posting so many times. Its ok to edit the post you made.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Yeah, Sorryz.
And....
Actually, it didn't work.
I used this code I used right after pspDebugScreenInit(); at the beginning of my main loop.

Code: Select all

	pspDebugScreenEnableBackColor(1);
	pspDebugScreenSetBackColor(0x00000000);
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You should be looking at examples more. There's TONS of PSP code floating around, and all of it works. Most emulators come with the source. Most games do as well. I've posted tests, apps, and game conversions here. Do more searching and looking at existing code. You don't seem prepared for this. More homework is needed. :)
Post Reply