Java Graphics Draw paintSprite(Graphics g, int x, int y, int[][] sprite, Color[] colors)

Here you can find the source of paintSprite(Graphics g, int x, int y, int[][] sprite, Color[] colors)

Description

Paint the given sprite.

License

Apache License

Parameter

Parameter Description
g a parameter
x a parameter
y a parameter
sprite a parameter
colors a parameter

Declaration

public static void paintSprite(Graphics g, int x, int y,
        int[][] sprite, Color[] colors) 

Method Source Code

//package com.java2s;
/*//from   www. ja v a 2 s .co  m
 * Copyright 2005 Patrick Gotthardt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.*;

public class Main {
    /**
     * Paint the given sprite. The value of the sprite array is the color to pick from the colors
     * array. If it is 0, nothing is painted. The first color (index 0 in colors) is qualified as 1.
     * @param g
     * @param x
     * @param y
     * @param sprite
     * @param colors
     */
    public static void paintSprite(Graphics g, int x, int y,
            int[][] sprite, Color[] colors) {
        for (int i = 0; i < sprite.length; i++) {
            for (int j = 0; j < sprite[i].length; j++) {
                if (sprite[i][j] == 0)
                    continue;
                g.setColor(colors[sprite[i][j] - 1]);
                g.drawLine(x + i, y + j, x + i, y + j);
            }
        }
    }
}

Related

  1. paintOval(int x, int y, Color c, int size, Graphics g)
  2. paintPoint(java.awt.Graphics g2, int x, int y)
  3. paintRectCompartment(Graphics g, Dimension size, int x, int y, Color fillColor, Color strokeColor)
  4. paintRectShadow(Graphics g, int x, int y, int width, int height)
  5. paintShape(Shape shape, Graphics2D g2d, Color colorStroke, Stroke stroke, Color colorFill, double downsample)
  6. prepareGraphics(Graphics g)
  7. printAll(java.awt.Graphics2D g2, java.awt.Component component)
  8. raiseOval(Graphics2D g2, Rectangle r, Color foreColor)
  9. raiseRect(Graphics2D g2, Rectangle r, Color foreColor)