some weird trails

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Hale
Posts: 9
Joined: Sat Apr 29, 2006 4:17 pm
Location: Gainesville, FL
Contact:

some weird trails

Post by Hale »

Hey, I'm still learning to use pngs in my programs and I kinda ran into some trouble. I was looking to make something along the lines of a disgaea cutscene (basically a background image + a character moves in from the right and another from the left, then they start talking etc)
like this: Image

unfortunately it's not really working. The image is leaving a trial and the animation is a bit blocky. I thought I'd fix the blocky movement by adding more iterations to the animation loop, but my real problem is the trails it's leaving behind.

here's my code and these images need to be placed in the same folders as the EBOOT.PBP (if you wana see the problem in action)

http://i87.photobucket.com/albums/k134/ ... ground.png
http://i87.photobucket.com/albums/k134/hale550/left.png

Code: Select all


#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>			//gives access to hardware acceleration also required by graphics.h
#include <png.h>			
#include <stdio.h>			//contains standard c functions
#include "graphics.h"		//includes functions for loading and displaying images



#define printf pspDebugScreenPrintf


void scroll_from_left&#40;Image*left_image&#41;;

PSP_MODULE_INFO&#40;"Sprite Test 4", 0, 1, 1&#41;;


/*setup callbacks to prevent psp from freezing or exiting at inappropirate times*/
/*----------------------------------------------------------------------------------------------------------------------------*/
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125;



/*----------------------------------------------------------------------------------------------------------------------------*/

/*start the program*/
int main&#40;&#41;
&#123;
	SceCtrlData pad;			//declare pad of type "sceCtrlData"

	char left_buffer&#91;200&#93;;			//path to left image
	char right_buffer&#91;200&#93;;			//path to right image
	char background_buffer&#91;200&#93;;	//path to right image

	Image*left;				//create an a variable "left" of type Image in graphics.h
	Image*right;			//create an a variable "right" of type Image in graphics.h
	Image*background;
	

	
	//program setup
	pspDebugScreenInit&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    initGraphics&#40;&#41;;			//gets the PSP ready to display graphics; it does all of the initial setup.

	sprintf&#40;left_buffer, "left.png"&#41;;					//print to a string the path to "left.png" in the variable "buffer"
	sprintf&#40;right_buffer, "right.png"&#41;;					//print to a string the path to "right.png" in the variable "buffer"
	sprintf&#40;background_buffer, "background.png"&#41;;		//print to a string the path to "background.png" in the variable "buffer"

    left = loadImage&#40;left_buffer&#41;;					//define left image
	right = loadImage&#40;right_buffer&#41;;				//define right image
	background = loadImage&#40;background_buffer&#41;;		//define right image
	
	sceDisplayWaitVblankStart&#40;&#41;;			//allows "home" button to work
	
	sceCtrlReadBufferPositive&#40;&pad, 1&#41;;		//read from control pad input
	
	blitAlphaImageToScreen&#40;0 ,0 ,480 , 272, background, 0,0&#41;;	//blit background
	flipScreen;													//flip background
	
	scroll_from_left&#40;left&#41;;										//animate left.png
			
	/*pause the program*/
	sceKernelSleepThread&#40;&#41;;

	return 0;
&#125;

// scroll image from left to right
void scroll_from_left&#40;Image*left_image&#41;
&#123;
	int x_offset;		//image offset from screen
	int image_width;	//png image width
	int i;				//counter

	image_width = left_image->imageWidth;	//find image width and store into "image_width"
	x_offset = 0 - image_width;				//determine what position on the screen the image should start out &#40;not currently visible&#41;

	blitAlphaImageToScreen&#40;0 ,0 ,image_width , 272, left_image	, x_offset,0&#41;;
	flipScreen&#40;&#41;;

	int incriment = image_width/10;			//divide the image width by the amount of frames &#40;i&#41; to define the incriment of movement
	for&#40;i=0;i<=10;i++&#41;						//animate image &#40;scroll onto screen&#41;
	&#123;	
		x_offset = x_offset + incriment;
		pspDebugScreenClear&#40;&#41;;				//clear the screen
		blitAlphaImageToScreen&#40;0 ,0 ,image_width , 272, left_image, x_offset,0&#41;;
		flipScreen&#40;&#41;;
		sceKernelDelayThread&#40;100000&#41;;		//wait for 1/10 of a second
	&#125;
	
	//position the image perfectly on the screen
	pspDebugScreenClear&#40;&#41;;
	blitAlphaImageToScreen&#40;0 ,0 ,image_width , 272, left_image, 0,0&#41;;
	flipScreen&#40;&#41;;

	return;
&#125;
standard Makefile:

Code: Select all

TARGET = sprite_practice4
OBJS = main.o graphics.o framebuffer.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LIBS = -lpspgu -lpng -lz -lm
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = sprite_practice4

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
And yes, I borrowed the background from guilty gear, but I'm just using it to test the program. Any help would be greatly appreciated. Thanks.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Two things: 1/10th of a second is a way too large timestep for smooth animation, and the PSP screen really is that slow when one of the colors involved have components (R G B, one or more) close to zero. Why, I don't know, but try brightening up your images a bit.
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

You're going about it all wrong, there's lots in your code that can be improved upon.

You don't need those 3 char buffers (left_buffer, right_buffer and background_buffer), you could just use one buffer for all 3.

In fact, you don't need a buffer at all.

Code: Select all

sprintf&#40;left_buffer, "left.png"&#41;;               //print to a string the path to "left.png" in the variable "buffer" 
   sprintf&#40;right_buffer, "right.png"&#41;;               //print to a string the path to "right.png" in the variable "buffer" 
   sprintf&#40;background_buffer, "background.png"&#41;;      //print to a string the path to "background.png" in the variable "buffer" 

    left = loadImage&#40;left_buffer&#41;;               //define left image 
   right = loadImage&#40;right_buffer&#41;;            //define right image 
   background = loadImage&#40;background_buffer&#41;;
Could be shortened to:

Code: Select all

left = loadImage&#40;"left.png"&#41;;               //define left image 
   right = loadImage&#40;"right.png"&#41;;            //define right image 
   background = loadImage&#40;"background.png"&#41;;
You want to be moving your image my smaller amounts too, and more frequently, I'd remove the 1/10th second delay for a start. I think you have too many calls to 'flipScreen()' too.
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

I counted 3 flipScreen()'s so in turn, it should display it still ;) lol...

Off = start

On = 1st
Off = 2nd
On = 3rd

:)
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

great gfx work ...a hint of fooly cooly
but thats just me :)
in your code the pspDebugScreenClears are used
way too much and really you dont need if your flipping
properly ...also
sceDisplayWaitVblankStart(); //allows "home" button to work
is in improper place ...after a flipscreen is best
so user does not detect ...also
/*pause the program*/
sceKernelSleepThread(); is not needed ...also
remove unneeded variables ...ill let you handle that :)
tip: start with image_width

sg57: eh? ...elaboration is the word :P
10011011 00101010 11010111 10001001 10111010
Post Reply