Will This Work?

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

Moderators: cheriff, TyRaNiD

Post Reply
snoopshady
Posts: 5
Joined: Thu Jan 10, 2008 1:49 am

Will This Work?

Post by snoopshady »

first of all i would like to say i have a little experience with C++ but only making windows command line apps.

Code: Select all

#include <pspdebug.h>
#include <pspkernel.h>
#include <pspcallbacks.h>
#include <pspctrl.h>
#include "graphics.h"

#define RGB&#40;r, g, b&#41; &#40;&#40;r&#41;|&#40;&#40;g&#41;<<8&#41;|&#40;&#40;b&#41;<<16&#41;&#41;
#define prints PrintTextScreen
PSP_MODULE_INFO&#40;"Sprite Movement",0,1,1&#41;;



void spritemove&#40;&#41;;

int main&#40;&#41;&#123;
initGraphics&#40;&#41;;
SetupCallbacks&#40;&#41;;
SceCtrlData pad;
Color white = RGB&#40;255,255,255&#41;;
int x = 200;
int y = 100;
Image*player = loadImage&#40;"Player2.png"&#41;;
while&#40;1&#41;&#123;
	sceCtrlPeekBufferPositive&#40;&pad,1&#41;;
	clearScreen&#40;white&#41;;
	if&#40;pad.Buttons & PSP_CTRL_LEFT &#41;&#123;
	spritemove&#40;&#41;;
	x--;
	&#125;
	blitAlphaImageToScreen&#40;0,0,18,30,player,x,y&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;
	flipScreen&#40;&#41;;
	&#125;
	return 0;
	&#125;
void spritemove&#40;&#41;&#123;
Image*player = loadImage&#40;"Player2.png"&#41;;
int ctr = 0;
ctr = ctr + 1;
int e = 0;
int d = 0;
int f = 0;
if&#40;ctr >= 40 || ctr <= 0&#41;&#123;
ctr = 0;
&#125;
if&#40;ctr == 10&#41;&#123;
player = loadImage&#40;"Player1.png"&#41;;
for&#40; d = 0; d < 3; d++&#41;&#123;
sceDisplayWaitVblankStart&#40;&#41;;
&#125;
&#125;
if&#40;ctr == 20&#41;&#123;
player = loadImage&#40;"Player2.png"&#41;;
for&#40;f = 0; f < 3; f++&#41;&#123;
sceDisplayWaitVblankStart&#40;&#41;;
&#125;
&#125;
if&#40;ctr == 30&#41;&#123;
player = loadImage&#40;"Player3.png"&#41;;
for&#40;e = 0; e < 3; e++&#41;&#123;
sceDisplayWaitVblankStart&#40;&#41;;
&#125;
&#125;
&#125;
Heres the code i normally use in lua (with C modifications) for animating sprites. I believe it should work (hey if it works in LUA technically shouldnt it work in C?). My question is does it?(Im pspless at the moment i cant test it). It compiles fine
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

well it might work then :)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

There are literally hundreds of "simple" sprite examples on the net in general, and this forum specifically. I even did one that loaded frames for animation from an anigif. Use the d@mn search and read the old threads!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

No it won't. Anyway, it will just crash at some point as it is constantly leaking memory.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Yeah, use the loadImage in the init, not the main sprite move function. That loads a new image every time it's called.
snoopshady
Posts: 5
Joined: Thu Jan 10, 2008 1:49 am

Post by snoopshady »

got it to work just changed this

Code: Select all

Image*player = loadImage&#40;"Player2.png"&#41;;
int ctr = 0;&#40;biggest mistake i made&#41; 
to this

Code: Select all

Image*player;
int ctr = 0;
and declared them as global variables
EDIT: also thanks Raphael and J.F
Post Reply