We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have a sprite sheet image that I load as a texture and display different subsections of the image with a combination of texture()
and vertex()
. Example:
size(480,320,P2D)
beginShape()
texture(...)
vertex(x,y,nx,ny)
vertex(x,y,nx,ny)
vertex(x,y,nx,ny)
vertex(x,y,nx,ny)
endShape()
The problem is I am now trying to run the sketch on a video device which doesn't have OpenGL (a Linux framebuffer) so I can't use P2D anymore. How can I achieve this same effect (drawing "windows" into a sprite sheet) without texture()
?
Would prefer not to split the spritesheet into hundreds of files if possible.
Answers
The copy () method will let you select a part of an image.
https://processing.org/reference/copy_.html
Unfortunately, copy() cannot copy arbitrary shapes, only rectangles. So you'll need to do it hard coded.
what arbitrary shapes? every sprite sheet i've ever seen has been nothing but rectangles.
https://www.google.co.uk/search?q=sprite+sheet&tbm=isch
Thanks koogs. copy() will work for me.
And yes, I'm using typical spritesheets so won't need to crop with non-rectangular outlines.
@koogs My mistake. I didn't notice the fact that it was a Sprite sheet being talked of (even if I did, I had no idea that Sprite sheets tend to have a rectangular space for each Sprite).
@westho -- although I don't believe it uses texture mapping, you might also be interested in the sprite sheet implementation in the S4P (Sprites for Processing) library by @quark
S4P will work with the default JAVA2D as well as the P2D/P3D renderers.