Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 10, 2012, 01:47:22 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Join our IRC channel: ##psp-programming on freenode
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: Background Doesnt Change  (Read 2232 times)
MailasG
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 45
0.00 points

View Inventory
Send Money to MailasG

View Profile
« on: October 18, 2006, 05:06:16 PM »

It only changes to both Back2.png and Back1.png then I press the L trigger:
Code:

if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 1))
{
Background = loadImage("./Images/Backgrounds/Back2.png");
currentBack = 2;
}
if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 2))
{
Background = loadImage("./Images/Backgrounds/Back3.png");
currentBack = 3;
}
if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 3))
{
Background = loadImage("./Images/Backgrounds/Back1.png");
currentBack = 1;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 1))
{
Background = loadImage("./Images/Backgrounds/Back3.png");
currentBack = 3;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 2))
{
Background = loadImage("./Images/Backgrounds/Back1.png");
currentBack = 1;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 3))
{
Background = loadImage("./Images/Backgrounds/Back2.png");
currentBack = 2;
}

And it doesnt change to back 3 when I press the L trigger, and it doesnt change at all when I press R. No errors though.
Logged


gibbocool
Embellished by our ignorance
News Posters
Hero Member
*

Karma: +34/-11
Offline Offline

Posts: 822
2973.87 points

View Inventory
Send Money to gibbocool

Power Overwhelming


View Profile WWW
« Reply #1 on: October 18, 2006, 05:20:44 PM »

Try a different approach:
load the backgrounds into an array. do this outside your game loop.

Code:

Image* backgroundArray[] = {loadImage("./Images/Backgrounds/Back1.png"), loadImage("./Images/Backgrounds/Back2.png"), loadImage("./Images/Backgrounds/Back3.png")};


then try this:

Code:

if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 1))
{
Background = backgroundArray[1];
currentBack = 2;
}
if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 2))
{
Background = backgroundArray[2];
currentBack = 3;
}
if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 3))
{
Background = backgroundArray[0];
currentBack = 1;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 1))
{
Background = backgroundArray[2];
currentBack = 3;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 2))
{
Background = backgroundArray[0];
currentBack = 1;
}
if((pad.Buttons & PSP_CTRL_LTRIGGER) && (currentBack == 3))
{
Background = backgroundArray[1];
currentBack = 2;
}
Logged

MailasG
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 45
0.00 points

View Inventory
Send Money to MailasG

View Profile
« Reply #2 on: October 18, 2006, 06:41:37 PM »

Well the arrays didn't work, just gave me errors so I tried another way, still doesnt change!!!!

Code:

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspgu.h>
#include <png.h>
#include <stdlib.h>
#include <string.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <psprtc.h>
extern "C"
{
#include "graphics.h"
}
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))

PSP_MODULE_INFO("MailasProduct", 0, 1, 1);

/* 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;
}

//GLOBAL VARIABLES
int main(void) {
    SetupCallbacks();
    initGraphics();

    SceCtrlData pad, lastpad;

    sceCtrlReadBufferPositive(&lastpad, 1);
   
    int MegaX = 27;
    int MegaY = 136;
   
    int ProtoX = 427;
    int ProtoY = 136;
   
    int megaPelX = 27;
   
    int shoot = 0;
    int currentBack = 1;

   
    Image* MegaImage;
MegaImage = loadImage("./Images/M_Plat.png");

    Image* ProtoImage;
ProtoImage = loadImage("./Images/P_Plat.png");

    Image* PelletImage;
PelletImage = loadImage("./Images/pellet.png");

Image* Background = loadImage("./Images/Backgrounds/Back1.png");




       while(1) {
      sceCtrlReadBufferPositive(&pad, 1);
     
if(pad.Buttons & PSP_CTRL_RIGHT)
{
shoot=1;
}

if(shoot==1) {
megaPelX+=1;
blitAlphaImageToScreen(0, 0, 8, 6, PelletImage, megaPelX, MegaY); }



if(MegaY > (272 - 26))
{
MegaY = (272 - 26);
}

if(MegaY < 0)
{
MegaY = 0;
}

if(ProtoY > (272 - 26))
{
ProtoY = (272 - 26);
}

if(ProtoY < 0)
{
ProtoY = 0;
}

if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 1))
{
Background = loadImage("./Images/Backgrounds/Back2.png");
currentBack = currentBack+1;
}

if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 2))
{
Background = loadImage("./Images/Backgrounds/Back3.png");
currentBack = currentBack+1;
}

if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 3))
{
Background = loadImage("./Images/Backgrounds/Back1.png");
currentBack = 1;
}







      if(pad.Buttons & PSP_CTRL_UP)
      {
       MegaY-=2;                    
      }
     
      if(pad.Buttons & PSP_CTRL_DOWN)
      {
       MegaY+=2;                    
      }
     
        if(pad.Buttons & PSP_CTRL_TRIANGLE)
      {
       ProtoY-=2;                    
      }
     
      if(pad.Buttons & PSP_CTRL_CROSS)
      {
       ProtoY+=2;                    
      }
     
      blitAlphaImageToScreen(0, 0, 480, 272, Background, 0, 0);
      blitAlphaImageToScreen(0, 0, 33, 26, MegaImage, MegaX, MegaY);
      blitAlphaImageToScreen(0, 0, 24, 25, ProtoImage, ProtoX, ProtoY);
     
       sceDisplayWaitVblankStart();
 flipScreen();

      }
      return 0;
      }


What ever I do it just wont change!
Logged
Insert_Witty_Name
Global Moderator
Hero Member
*

Karma: +149/-17
Offline Offline

Posts: 1602
1141.66 points

View Inventory
Send Money to Insert_Witty_Name

View Profile WWW
« Reply #3 on: October 18, 2006, 10:13:13 PM »

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspgu.h>
#include <png.h>
#include <stdlib.h>
#include <string.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <psprtc.h>
extern "C"
{
#include "graphics.h"
}
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))

PSP_MODULE_INFO("MailasProduct", 0, 1, 1);

/* 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;
}

//GLOBAL VARIABLES
int main(void) {
    SetupCallbacks();
    initGraphics();

    SceCtrlData pad, lastpad;

    sceCtrlReadBufferPositive(&lastpad, 1);
   
    int MegaX = 27;
    int MegaY = 136;
   
    int ProtoX = 427;
    int ProtoY = 136;
   
    int megaPelX = 27;
   
    int shoot = 0;
    int currentBack = 0;

   
    Image* MegaImage;
MegaImage = loadImage("./Images/M_Plat.png");

    Image* ProtoImage;
ProtoImage = loadImage("./Images/P_Plat.png");

    Image* PelletImage;
PelletImage = loadImage("./Images/pellet.png");

Image* Background[3];
Background[0] = loadImage("./Images/Backgrounds/Back1.png");
Background[1] = loadImage("./Images/Backgrounds/Back2.png");
Background[2] = loadImage("./Images/Backgrounds/Back3.png");

       while(1) {
      sceCtrlReadBufferPositive(&pad, 1);
     
if(pad.Buttons & PSP_CTRL_RIGHT)
{
shoot=1;
}

if(shoot==1) {
megaPelX+=1;
blitAlphaImageToScreen(0, 0, 8, 6, PelletImage, megaPelX, MegaY);
}



if(MegaY > (272 - 26))
{
MegaY = (272 - 26);
}

if(MegaY < 0)
{
MegaY = 0;
}

if(ProtoY > (272 - 26))
{
ProtoY = (272 - 26);
}

if(ProtoY < 0)
{
ProtoY = 0;
}

if(pad.Buttons & PSP_CTRL_RTRIGGER)
{
  (currentBack < 2) ? currentBack++ : currentBack = 0;
}

      if(pad.Buttons & PSP_CTRL_UP)
      {
       MegaY-=2;
      }
     
      if(pad.Buttons & PSP_CTRL_DOWN)
      {
       MegaY+=2;                    
      }
     
        if(pad.Buttons & PSP_CTRL_TRIANGLE)
      {
       ProtoY-=2;                    
      }
     
      if(pad.Buttons & PSP_CTRL_CROSS)
      {
       ProtoY+=2;                    
      }
     
      blitAlphaImageToScreen(0, 0, 480, 272, Background[currentBack], 0, 0);
      blitAlphaImageToScreen(0, 0, 33, 26, MegaImage, MegaX, MegaY);
      blitAlphaImageToScreen(0, 0, 24, 25, ProtoImage, ProtoX, ProtoY);
     
       sceDisplayWaitVblankStart();
 flipScreen();

      }
      return 0;
      }
Logged

Coder formerly known as:

Check out my homebrew & C tutorials at http://insomniac.0x89.org
Last updated 6th Oct 06 - Tutorial 2 added.
MailasG
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 45
0.00 points

View Inventory
Send Money to MailasG

View Profile
« Reply #4 on: October 19, 2006, 03:02:54 PM »

Im really sorry, i wasn't asking for a whole peice of code though like you always have to do it all for me, but atleast now I know how to use arrays.

I know you're probably really annoyed at me right now, so Im sorry.
Logged
Insert_Witty_Name
Global Moderator
Hero Member
*

Karma: +149/-17
Offline Offline

Posts: 1602
1141.66 points

View Inventory
Send Money to Insert_Witty_Name

View Profile WWW
« Reply #5 on: October 19, 2006, 07:03:59 PM »

Don't apologise mate.

If I was 'annoyed' I wouldn't have helped at all Wink
Logged

Coder formerly known as:

Check out my homebrew & C tutorials at http://insomniac.0x89.org
Last updated 6th Oct 06 - Tutorial 2 added.
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.782 seconds with 30 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com