it says it out of bounds
String [] suit = {"Clubs", "Diamonds", "Hearts", "Spades"};
String [] rank ={"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
String [] deckofCards=new String [rank.length*suit.length];
int a;
int b;
int temp;
int numFrames=52;
PImage [] images= new PImage[numFrames];
int frame=0;
float x=0;
obviously when displaying images all on top of each other (same x and y position), you'll see only the last image (the screen is only updated once at the end of draw() (each time the sketch gets there) and not throughout)
Here is an example that demonstrates drawing things at different positions based on the x and y values used to do the looping, as well as a way to have your sketch draw different things depending on which state it is in.
Yes. You already have code that detects when different keys are pressed. Depending on which key was pressed, you can set your sketch's state to a different value, and draw different things based on the current value of the state variable.
another problem Im having is that if I press the s key first, "null" comes out,
I have to press the d key first inorder for the s key to display normal
You should probably give each of your array's strings a starting value. I would do this in setup(), using a loop. It's actually the same thing you're doing as when the 'd' key is pressed. You might want to move that code into a new function, and just call it twice.
At this point there is a lot of help that has been given to you. The latest code you have posted does not reflect any of the advice you have been given. If you need more help, please attempt to resolve the existing issues first, and post the formatted version of your attempt.
Answers
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
https://forum.Processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking
you mean show the images when hitting key d ?
ok, first, you don't need to load all images again - you loaded them in setup() and that is what setup() is for.
second, you need to say frame=0; before the 2 for loops and then say frame++; after println() to go on to the next image
it says it out of bounds String [] suit = {"Clubs", "Diamonds", "Hearts", "Spades"}; String [] rank ={"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"}; String [] deckofCards=new String [rank.length*suit.length]; int a; int b; int temp; int numFrames=52; PImage [] images= new PImage[numFrames]; int frame=0; float x=0;
void setup(){ size(600,400); background(0);
frameRate(2);
for(int i=0;i<images.length;i++){ String imageName = "cards-"+i+".png"; images[i]=loadImage(imageName);
}
}
void draw(){
frame=frameCount%numFrames;}
void mousePressed(){ int a=(int)(random(rank.length)); int b=(int)(random(suit.length)); println(rank[a]+" "+"of"+" "+suit[b]);
}
void keyPressed(){ if (key=='d'){ frame=0;
}}}
else if(key== 's'){ int t=deckofCards.length; for( int c=0; c<t;c++){ int l=c+ (int)(random(t-c));
println(deckofCards[c]);}}}
is
rank.length*suit.length
== 51 ?because you have the array this size
learn how to format code
go back, edit your post and format the
code
correctlyno its 52 i fixed it, but the images still won't play, what could be wrong?
go back, edit your sketch and format the code correctly
obviously when displaying images all on top of each other (same x and y position), you'll see only the last image (the screen is only updated once at the end of
draw()
(each time the sketch gets there) and not throughout)to solve this set/ say
frameRate(12);
and then make a state "display"
start this state and in
draw()
don't use for loop but justPlease format your code for this forum. You have been asked 3 times in this discussion to format your code and you have completely ignored them.
Making your code legible makes it easier for members help you!
If you don't know how to do it then read this discussion and then go back and edit your comments above.
my apologies, here is my code, please help make images appear after I Press d
I told you how to do it
it didn't work
show your attempt
;-)
could you clarify how to fix it?, I don't think I understood?
What do you mean by state display?
Here is an example that demonstrates drawing things at different positions based on the x and y values used to do the looping, as well as a way to have your sketch draw different things depending on which state it is in.
I can apply this to pressing different keys?
Yes. You already have code that detects when different keys are pressed. Depending on which key was pressed, you can set your sketch's state to a different value, and draw different things based on the current value of the state variable.
another problem Im having is that if I press the s key first, "null" comes out, I have to press the d key first inorder for the s key to display normal
That's because you are trying to get values from your deckOfCards array before you've assigned any string values to them!
how is this fixed please? <3
You should probably give each of your array's strings a starting value. I would do this in setup(), using a loop. It's actually the same thing you're doing as when the 'd' key is pressed. You might want to move that code into a new function, and just call it twice.
At this point there is a lot of help that has been given to you. The latest code you have posted does not reflect any of the advice you have been given. If you need more help, please attempt to resolve the existing issues first, and post the formatted version of your attempt.
I see, well thanks for the attempt