forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

some weird trails

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Hale



Joined: 29 Apr 2006
Posts: 9
Location: Gainesville, FL

PostPosted: Wed Aug 02, 2006 6:30 am    Post subject: some weird trails Reply with quote

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:

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/hale550/background.png
http://i87.photobucket.com/albums/k134/hale550/left.png
Code:


#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(Image*left_image);

PSP_MODULE_INFO("Sprite Test 4", 0, 1, 1);


/*setup callbacks to prevent psp from freezing or exiting at inappropirate times*/
/*----------------------------------------------------------------------------------------------------------------------------*/
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}



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

/*start the program*/
int main()
{
   SceCtrlData pad;         //declare pad of type "sceCtrlData"

   char left_buffer[200];         //path to left image
   char right_buffer[200];         //path to right image
   char background_buffer[200];   //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();
    SetupCallbacks();
    initGraphics();         //gets the PSP ready to display graphics; it does all of the initial setup.

   sprintf(left_buffer, "left.png");               //print to a string the path to "left.png" in the variable "buffer"
   sprintf(right_buffer, "right.png");               //print to a string the path to "right.png" in the variable "buffer"
   sprintf(background_buffer, "background.png");      //print to a string the path to "background.png" in the variable "buffer"

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

   return 0;
}

// scroll image from left to right
void scroll_from_left(Image*left_image)
{
   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 (not currently visible)

   blitAlphaImageToScreen(0 ,0 ,image_width , 272, left_image   , x_offset,0);
   flipScreen();

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

   return;
}


standard Makefile:
Code:
TARGET = sprite_practice4
OBJS = main.o graphics.o framebuffer.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

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

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = sprite_practice4

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/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.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Wed Aug 02, 2006 6:46 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Wed Aug 02, 2006 7:53 am    Post subject: Reply with quote

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:
sprintf(left_buffer, "left.png");               //print to a string the path to "left.png" in the variable "buffer"
   sprintf(right_buffer, "right.png");               //print to a string the path to "right.png" in the variable "buffer"
   sprintf(background_buffer, "background.png");      //print to a string the path to "background.png" in the variable "buffer"

    left = loadImage(left_buffer);               //define left image
   right = loadImage(right_buffer);            //define right image
   background = loadImage(background_buffer);


Could be shortened to:

Code:
left = loadImage("left.png");               //define left image
   right = loadImage("right.png");            //define right image
   background = loadImage("background.png");


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.
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Wed Aug 02, 2006 12:55 pm    Post subject: Reply with quote

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

Off = start

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

:)
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Wed Aug 02, 2006 1:57 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group