Trying to recreate undertale in processing

Hi I haven’t used processing for so long and i am kinda new to programming. I decided to challenge myself by trying to recreate the videogame undertale because I thought it would be a fun thing to spend my time on. I have tried to make the intro where i have to load around 10 pictures to make a slide show but when i run my program it uses some time before all the pictures have loaded. I think this can be solved by not loading all the pictures at once but instead load them along the way.

If someone knows the solution to the problem it would be nice to see a/some example(s)

1 Like

Some code of what you already have can be helpful for others to help you :wink:

What you probably want to do, is to load the first Image before Starting the slideshow and then load the Next Image When the Next Part begins.
Something like this :
Load image1; Start slideshow; load Image2; Show image1; load image3; show image2; and so on.

//here is what i have made so far
// some of it is in danish but it is not important and just so i can remember what i have done

import processing.sound.*;
SoundFile intro;
PImage img;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img10;
PImage img11;
boolean a=true;
boolean b=false;
int lts = 0;
int davs()
{
  return lts++;
}
String test = "Long ago, two races ruled over Earth: HUMAN and MONSTERS. ";
String text2 = "One day, war broke out between the two races.";
String text3 ="After a long battle, the humans were victorious.";
String text4 ="They sealed the monsters underground with a magic spell.";
String text5 ="Many years later...";
String text6 ="MT.  EBOTT 202X";
String text7 ="Legends say that those who climb the mountain never return.";
void setup()
{
  fullScreen();
  intro = new SoundFile(this, "intro.mp3");
  
  img= loadImage("1.jpg"); 
  img2= loadImage("2.jpg");
  img3= loadImage("3.png");
  img4=loadImage("4.jpg");
  img5=loadImage("5.JPG");
  img6=loadImage("6.JPG");
  img7=loadImage("7.JPG");
  img8=loadImage("8.JPG");
  img9=loadImage("9.png");
  img10=loadImage("Undertale2.png");
  
 
  frameRate(12);
}

void draw(){
  background(0);
  davs();
 println(frameCount);
 textSize(40);
 textMode(CENTER);
 imageMode(CENTER);
//så jeg kan komme hurtigere frem og tilbage mellem billederne (hold knappen inde))

if(keyPressed){
  if(keyCode==27){
    exit();
}}

//if (frameCount<=0 && frameCount <1056 && keyPressed){

//}

if (frameCount==1){
 intro.play();
}

if (frameCount<=0 && frameCount<1500)
{
  a=true;
}
if (a==true){
if (frameCount>1 && frameCount<1056){
  if(keyPressed){
    if (keyPressed)
    {  
      if (key== 10)
    {
       frameCount=1056;
     }
   }
}
}
  
 //første slide og tekst 0-7 sec
if (frameCount<94){ 
image(img,width/2,300,700,500);
if (lts<=test.length())
{
text( test.substring(0,lts), 650,700, 600,300);
}
else
{
text(test,650,700,600,300);
}
}
//hvis framecounten bliver større end 80 skal ny tekst skrives

//anden slide og tekst 7-14
if (frameCount==94)
{
  lts=0; //når framecount er 80 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=94 && frameCount<168){ 
image(img2,width/2,300,700,500);
if (lts<=text2.length())
{
text( text2.substring(0,lts), 650,700, 680,300);
}
else
{
text(text2,650,700,680,300);
}
}

//tredje slide efter en lang kamp 14-20
if (frameCount==168)
{
  lts=0; //når framecount er 160 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=168 && frameCount<240){ 
image(img3,width/2,300,700,500);
if (lts<=text3.length())
{
text( text3.substring(0,lts), 650,700, 680,300);
}
else
{
text(text3,650,700,680,300);
}
}

//fjerde slide they sealed 20-25
if (frameCount==240)
{
  lts=0; //når framecount er 160 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=240 && frameCount<300){ 
image(img3,width/2,300,700,500);
if (lts<=text4.length())
{
text( text4.substring(0,lts), 650,700, 680,300);
}
else
{
text(text4,650,700,680,300);
}
}

//femte slide (many years later) og tekst 25- 30
if (frameCount==300)
{
  lts=0; //når framecount er 160 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=300 && frameCount<360){ 
if (lts<=text5.length())
{
text( text5.substring(0,lts), 780,700, 680,300);
}
else
{
text(text5,780,700,680,300);
}
}

//sjette slide (MT.ebott) og tekst 30-35
if (frameCount==360)
{
  lts=0; //når framecount er 160 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=360 && frameCount<420){
  image(img4,width/2,300,700,500);
if (lts<=text6.length())
{
text( text6.substring(0,lts), 780,700, 400,300);
}
else
{
text(text6,780,700,400,300);
}
}

//syvende slide legends say 35-42 
if (frameCount==420)
{
  lts=0; //når framecount er 160 reset lts så teksten kommer op som bogstav efter bogstav
}
if (frameCount>=420 && frameCount<504){ 
image(img5,width/2,300,700,500);
if (lts<=text7.length())
{
text( text7.substring(0,lts), 650,700, 680,300);
}
else
{
text(text7,650,700,680,300);
}
}

//ottende slide (kigge) uden tekst 42-47
if (frameCount>=504 && frameCount<600){ 
image(img6,width/2,300,700,500);
}

//niende slide uden tekst (snuble) 47-53 
if (frameCount>=600 && frameCount<708){ 
image(img7,width/2,300,700,500);
}

//tiende slide uden tekst (falde) 53-59
if (frameCount>=708 && frameCount<816){ 
image(img8,width/2,300,700,500);
}

//11. slide uden tekst (ligge) 69-90
if (frameCount>=816 && frameCount<1056){ 
image(img9,width/2,500,600,850);
}

if (frameCount==1056){
  intro.stop();
}

textSize(40);
//12. slide UNDERTALE!
if (frameCount>=1080 && frameCount<1500){ 
image(img10,width/2,500,1980,1080);
}
if(frameCount>=1116 && frameCount<1500){
  text("Pres 2 or Enter",750,700,600,300);
}
}

if (frameCount>1056){
  if(keyPressed){
    if (keyPressed)
    {  
      if (key== 10)
    {
       frameCount=1500;
     }
   }
}
}

if (frameCount>1056){
  if(keyPressed){
    if (keyPressed)
    {  
      if (key== 50)
    {
       frameCount=1500;
     }
   }
}
}
} //lukker void draw
1 Like

If you post Code, please make sure it is formatted, to make it easier to read. And i‘m still pretty sure that you should just load the Next Image while the previous one is shown. Btw, i don’t think it is a good idea to manually set the frameCount. I don‘t know if it does, But it could cause internal problems.

it’s only a measurement of time and i only have to use it in the start so it doesn’t matter later on. It would be nice if i could see an example of loading a picture before using it later on

Try to replace it with

if (frameCount <= 94) {
img2 = loadImage(„2.jpg“);
image(img, x, y, h, w);
}

if (frameCount > 94 && frameCount < 168) {
img3 = loadImage(„img3.png“);
image(img2, x, y, h, w);
}

And so on. Also delete the previous Part where all Images are Loaded at once, except the first Image. This way they all get loaded while the previous Image is shown.

thank you. I have thought about trying that but i didn’t know if the image still would be loaded if i wanted to use it later. This works with sound too right?

Sorry, i Never worked with sound, so i don‘t know, But it should.

Keep in mind that, if you have 10 images, you can use an array of images.

PImage[] imgs = new PImage[10];
imgs[0] = loadImage("1.jpg"); 
imgs[1] = loadImage("2.jpg");

This makes code a lot easier to read if you have 20, or 50, or 100 images, or need to load a directory of images.

For more on arrays and array access, see:

If you have a display img and a bunch of resources, you can map them to display like this:

void draw(){
  switch(frameCount){
    case 1:
    imgdisplay = img1;
    break;
    case 94:
    imgdisplay = img2;
    break;
    case 168:
    imgdisplay = img3;
    break;
  }
  image(imgdisplay, width/2, 300, 700, 500);
}

Now you always display the imgdisplay PImage, but on certain specific frames you redefine which other image it points to.

1 Like

Can you share the full code as well as the sound and image files?