SIMPLEST way to sprites screenDrawGraphic( img, x, y, angle, sizeX, sizeY, alpha );

edited February 2016 in Share Your Work

img = Any PImage object. x = x cordinate to draw image. y = y cordinate to draw image. angle = IN DEGREES! the angle of rotation for draw image. sizeX = in %, 100= original sizeX, 200 is double width etc etc.. sizeY = same has sizeX.. alpha = from 0 to 255.. this is the transparency for image draw.

ENJOY! ;)

void screenDrawGraphic(PImage img_, float x, float y, float angle, int sizeX, int sizeY, int alpha){
  pushMatrix();
  imageMode(CENTER);
  int w = (img_.width * sizeX) / 100;
  int h = (img_.height * sizeY) / 100;
  tint(255, alpha);
  translate(x,y);
  rotate(radians(angle));
  image(img_, 0, 0, w, h);
  popMatrix();
}

Comments

  • Thanks :)
    With:
    rotate(radians(angle), x, y, z)
    the image can rotate around any axis (using P3D ;) ).

  • I would also use pushStyle() and popStyle() otherwise the tint will affect graphics drawn after calling your function.

  • Thanks for this info ;)

Sign In or Register to comment.