/** * 将LImage转化为LTextureData * * @param image * @return */ private void create(LImage image) { if (image == null) { return; } int srcWidth = image.getWidth(); int srcHeight = image.getHeight(); this.hasAlpha = image.hasAlpha(); if (GLEx.isPowerOfTwo(srcWidth) && GLEx.isPowerOfTwo(srcHeight)) { this.width = srcWidth; this.height = srcHeight; this.texHeight = srcHeight; this.texWidth = srcWidth; this.source = image.getByteBuffer(); this.pixels = image.getPixels(); if (image.isAutoDispose()) { image.dispose(); image = null; } return; } int texWidth = GLEx.toPowerOfTwo(srcWidth); int texHeight = GLEx.toPowerOfTwo(srcHeight); this.width = srcWidth; this.height = srcHeight; this.texHeight = texHeight; this.texWidth = texWidth; LImage texImage = new LImage(texWidth, texHeight, hasAlpha); LGraphics g = texImage.getLGraphics(); g.drawImage(image, 0, 0); if (this.height < texHeight - 1) { copyArea(texImage, g, 0, 0, width, 1, 0, texHeight - 1); copyArea(texImage, g, 0, height - 1, width, 1, 0, 1); } if (this.width < texWidth - 1) { copyArea(texImage, g, 0, 0, 1, height, texWidth - 1, 0); copyArea(texImage, g, width - 1, 0, 1, height, 1, 0); } this.source = texImage.getByteBuffer(); this.pixels = texImage.getPixels(); if (image.isAutoDispose()) { image.dispose(); image = null; } }
public void setTileBackground(LImage image) { if (image == null) { return; } int layerWidth = getWidth(); int layerHeight = getHeight(); int tileWidth = image.getWidth(); int tileHeight = image.getHeight(); LImage background = LImage.createImage(layerWidth, layerHeight, false); LGraphics g = background.getLGraphics(); for (int x = 0; x < layerWidth; x += tileWidth) { for (int y = 0; y < layerHeight; y += tileHeight) { g.drawImage(image, x, y); } } g.dispose(); setBackground(background); }
public void paintObjects(LGraphics g, int minX, int minY, int maxX, int maxY) { if (objects == null) { return; } synchronized (objects) { int paintSeq = 0; boolean isListener = false; Iterator iter = objects.iterator(); Actor thing = null; while (iter.hasNext()) { thing = (Actor) iter.next(); if (!thing.isVisible()) { continue; } isListener = (thing.actorListener != null); thing.update(elapsedTime); if (isListener) { thing.actorListener.update(elapsedTime); } RectBox rect = thing.getRectBox(); int actorX = minX + thing.getX(); int actorY = minY + thing.getY(); int actorWidth = rect.getWidth(); int actorHeight = rect.getHeight(); if (actorX + actorWidth < minX || actorX > maxX || actorY + actorHeight < minY || actorY > maxY) { continue; } LImage actorImage = thing.getImage(); if (actorImage != null) { thing.setLastPaintSeqNum(paintSeq++); boolean isBitmapFilter = ImageFilterType.NoneFilter != thing.filterType; Image bitmap = actorImage.getBufferedImage(); if (isBitmapFilter) { bitmap = factory.doFilter(bitmap, thing.filterType); } int rotation = thing.getRotation(); if (thing.alpha < 1.0) { g.setAlpha(thing.alpha); } if (rotation != 0) { double halfWidth = actorImage.getWidth() / 2; double halfHeight = actorImage.getHeight() / 2; double newWidth = actorX + halfWidth; double newHeight = actorY + halfHeight; atform.setToIdentity(); atform.scale(thing.scaleX, thing.scaleY); atform.translate(newWidth, newHeight); atform.rotate(Math.toRadians(rotation)); atform.translate(-newWidth, -newHeight); atform.translate(actorX, actorY); g.drawImage(bitmap, atform); } else { int width = (int) (actorImage.getWidth() * thing.scaleX); int height = (int) (actorImage.getHeight() * thing.scaleY); g.drawImage(bitmap, actorX, actorY, width, height); } if (isBitmapFilter) { bitmap.flush(); bitmap = null; } if (thing.alpha < 1.0) { g.setAlpha(1.0F); } } if (actorX == 0 && actorY == 0) { thing.draw(g); if (isListener) { thing.actorListener.draw(g); } } else { g.translate(actorX, actorY); thing.draw(g); if (isListener) { thing.actorListener.draw(g); } g.translate(-actorX, -actorY); } } } }