We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm a beginner and I'm trying to code a mildly interactive digital story book using my own illustrations. The idea is that when you open up the program you can choose one of two characters to see their story, and upon completing their story you go back to the beginning and have to choose the other story to get full experience. I'm having trouble coding it such that with each press of the RIGHT key it will go to the next image like you're flipping though pages. I got the first part down where you can choose the first character within those specific coordinates, but I'm stuck beyond what I've done here. Any help would be greatly appreciated.
PImage img, img2, img3, img4;
void setup() {
size (950, 1000);
img= loadImage("Start page.jpg");
img2= loadImage("Page (1-1).jpg");
img3= loadImage("Page (1-2).jpg");
img4= loadImage("Page (1-3).jpg");
image(img, 0, 0);
}
void draw () {
if ((mouseX>425)&&(mouseX<900)) {
if (mousePressed==true) {
image(img2, 0, 0);
}
if (keyCode==RIGHT) {
image(img3, 0, 0);
}
if(keyCode==RIGHT){ //this is obviously not the correct course of action but is where I am stuck
image(img4,0,0);
}
}
}
Answers
that’s not the way.
Idea
Better look at array and load your images in the array (which is a list of images)
Then when RIGHT is pressed just increase the line number (index) so that the next image is shown
In Code
PImage [] imagesMy = new PImage[4];
load images into the slots of the array
image( imagesMy[currImg], 0,0);
use this as a new function not in draw()!!!!
if.... currImg++;
Best regards, Chrisir ;-)
https://processing.org/tutorials/arrays/
Additionally: for extra features like select character you want an extra screen this would be a new int variable named state which tells you which state you are in
BrowseBook would be one (see above), choose character another, finished book page a 3rd state (for example)
That makes sense, I figured I'd have to do something with arrays. Thanks for clarifying, I'm on the right track now
a new version with a state system to distinguish between start screen and the pages of the book
Interesting, I neglected to include the fact that there more than 4 images however. There is a starting page, 4 pages for one character, 4 for the other character, and then they share the final page at which point you would be taken back to the beginning if it is your first time through either of the stories. This is where I got with regards to your first reply.
I attempted including your updated code into my own version, but I couldn't get it to work. Also there would have to be an alternate mousePressed input such that you choose the other character. Also just for reference this is a sketch of what the start page will look like.
Beautiful image - I‘d love to see the book.
Can’t wait.
You should also find a publisher.
Anyway, your code looks good!
Technically my code is better, but let’s work with your code:
You can make another mouse Check in mousePressed. if (moouseX..... Then you could set a variable characterChosen to 1 or 2 depending on the area clicked.
Now you could have a second image array for the other pages. Declare before setup, fill in setup, like you did with your first array
In keyPressed depending on var characterChosen you would load either from the array1 or from the array2 into the image you use in draw (). if(characterChosen==1) imagesMay=....
I am writing this because you seem to have two different sets of images
So this
imagesMy[i]= loadImage("Page"+i+".jpg");
Would be accompanied by a second line
imagesMySecondSet[i]= loadImage("SecondSetPage"+i+".jpg");
or so...
Nice project!
Thank you very much :3 I had a chance to work with my teaching assistant earlier and he managed to help me figure it out for the most part
I wanted to make it so that once you get to the end of one story it replaces the first image with a grayed out version of the character you chose such that it indicates that you should choose the other character. It may be a bit complicated to implement, but as long as I have this basic structure in place I won't necessarily be dissatisfied with the final result. Now I just have to get to drawing the damn things. I'll try and get it up on the net for people to see once it's done. Thanks for all the help.
https://processing.org/reference/tint_.html for changing transparency
https://processing.org/reference/PImage_blend_.html would be another approach
Kf
@ambigsby --
Interesting electronic literature form, great concept art.
This reminds me a bit of the menu interface to The Path by Tale of Tales.
As you evolve from being a beginner, this might be a great example of how to use classes to create a general StoryBook framework.