We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to build a memory card game in Processing 2. So far it's going pretty well, the only thing that eludes me is how to apply textures to shapes.
I load and resize the image in the setup()
. The image is being resized by cardBack.resize(tileSizeX, tileSizeY)
to fit the size of the shape.
Then on draw()
I try to draw the shape like this:
beginShape(QUADS);
fill(0, 200, 0);
vertex(-(tileSizeX / 2), -(tileSizeY / 2), -1, 0, 0);
vertex(tileSizeX / 2, -(tileSizeY / 2), -1, tileSizeX, 0);
vertex(tileSizeX / 2, tileSizeY / 2, -1, tileSizeX, tileSizeY);
vertex(-(tileSizeX / 2), tileSizeY / 2, -1, 0, tileSizeY);
texture(cardBack);
vertex(-(tileSizeX / 2), -(tileSizeY / 2), 0);
vertex(tileSizeX / 2, -(tileSizeY / 2), 0);
vertex(tileSizeX / 2, tileSizeY / 2, 0);
vertex(-(tileSizeX / 2), tileSizeY / 2, 0);
endShape(CLOSE);
The result is a card with two sides. The down side is green and the upper side is gray-ish. I'm not really seeing what's going wrong here. This is my first project in processing, so I could really use some assistance.
Answers
I made a comment here that was wrong -- so I have deleted it -- now I have a question. Shouldn't you have two separate beginShape()s -- one for the front and one for the back? Your question text seems to be about texture(), and I think that may not be the problem. It may be just that you need two shapes.
From the texture() reference:
Clair is right, you have to use two distinct beginShape/endShape calls to create the card and you have to set the texture before any vertex call. The following code should work (untested):