本文整理汇总了Java中playn.core.Image类的典型用法代码示例。如果您正苦于以下问题:Java Image类的具体用法?Java Image怎么用?Java Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Image类属于playn.core包,在下文中一共展示了Image类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getSprite
import playn.core.Image; //导入依赖的package包/类
private static Sprite getSprite (final Platform plat, String jsonPath, final Image[] images) {
final RPromise<Sprite> state = RPromise.create();
final Sprite sprite = new Sprite(state);
// load and parse json
plat.assets().getText(jsonPath).onFailure(state.failer()).onSuccess(new Slot<String>() {
@Override public void onEmit (String json) {
try {
loadSprite(plat, images, sprite, plat.json().parse(json), state);
} catch (Throwable err) {
err.printStackTrace(System.err);
state.fail(err);
}
}
});
return sprite;
}
开发者ID:playn,项目名称:playn-samples,代码行数:17,代码来源:SpriteLoader.java
示例2: HelloGame
import playn.core.Image; //导入依赖的package包/类
public HelloGame(Platform plat) {
super(plat, 25); // 25 millis per frame = ~40fps
// combine mouse and touch into pointer events
pointer = new Pointer(plat);
// create and add background image layer
Image bgImage = plat.assets().getImage("images/bg.png");
ImageLayer bgLayer = new ImageLayer(bgImage);
bgLayer.setSize(plat.graphics().viewSize);
rootLayer.add(bgLayer);
// create a group layer to hold the peas
final GroupLayer peaLayer = new GroupLayer();
rootLayer.add(peaLayer);
// when the pointer is tapped/clicked, add a new pea
pointer.events.connect(new Slot<Pointer.Event>() {
@Override public void onEmit (Pointer.Event event) {
if (event.kind.isStart) new Pea(peaLayer, event.x(), event.y());
}
});
}
开发者ID:playn,项目名称:playn-samples,代码行数:24,代码来源:HelloGame.java
示例3: startLoadingImages
import playn.core.Image; //导入依赖的package包/类
private void startLoadingImages() {
List<RFuture<Image>> futures = SimGame.game.assets.cache(GameAssets.ImageKey.values());
for (RFuture<Image> future : futures) {
future.onSuccess(new Slot<Image>() {
@Override
public void onEmit(Image image) {
progressBar.increment();
}
});
future.onFailure(new Slot<Throwable>() {
@Override
public void onEmit(Throwable throwable) {
SimGame.game.plat.log().warn("Failed to load image", throwable);
}
});
}
RFuture.collect(futures).onSuccess(new Slot<Collection<Image>>() {
@Override
public void onEmit(Collection<Image> tiles) {
countDown();
}
});
}
开发者ID:social-startup-game,项目名称:social-startup-game,代码行数:24,代码来源:LoadingScreen.java
示例4: visit
import playn.core.Image; //导入依赖的package包/类
@Override
public void visit(Widget widget, TexturedBackground background) {
IAnimationFrame frame = background.getPlay().getCurrentFrame();
if (null != frame) {
Image image = (Image) frame.getImage().getId();
surface.save();
surface.translate(widget.getX() + widget.getWidth()/2.0f, widget.getY()+widget.getHeight()/2.0f);
surface.scale(background.isMirrorX() ? -1.0f : 1.0f, background.isMirrorY() ? -1.0f : 1.0f);
surface.drawImage(image,
-widget.getWidth()/2.0f,
-widget.getHeight()/2.0f,
widget.getWidth(),
widget.getHeight(),
frame.getU1() * image.width(),
frame.getV1() * image.height(),
(frame.getU2() - frame.getU1()) * image.width(),
(frame.getV2() - frame.getV1()) * image.height());
surface.restore();
}
}
开发者ID:devnewton,项目名称:jnuit,代码行数:21,代码来源:PlaynNuitRenderer.java
示例5: SpriteImage
import playn.core.Image; //导入依赖的package包/类
public SpriteImage(final Image image, int x, int y, int width, int height) {
this.image = image;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
开发者ID:playn,项目名称:playn-samples,代码行数:8,代码来源:SpriteImage.java
示例6: create
import playn.core.Image; //导入依赖的package包/类
@Override public void create (final Showcase game, Closeable.Set onClose) {
// create a group layer to hold everything
final GroupLayer layer = new GroupLayer();
game.rootLayer.add(layer);
onClose.add(layer);
// load a sound that we'll play when placing sprites
final Sound ding = game.plat.assets().getSound("sprites/ding");
// create and add background image layer
Image bgImage = game.plat.assets().getImage("background.png");
IDimension viewSize = game.plat.graphics().viewSize;
ImageLayer bg = new ImageLayer(bgImage).setSize(viewSize);
layer.add(bg);
final List<Pea> peas = new ArrayList<>();
// add a listener for pointer (mouse, touch) input
bg.events().connect(new Pointer.Listener() {
public void onStart (Pointer.Interaction iact) {
peas.add(newPea(game.plat, layer, ding, iact.event.x, iact.event.y));
}
});
peas.add(newPea(game.plat, layer, ding, viewSize.width() / 2, viewSize.height() / 2));
onClose.add(game.paint.connect(new Slot<Clock>() {
public void onEmit (Clock clock) {
for (Pea pea : peas) pea.update(clock);
}
}));
}
开发者ID:playn,项目名称:playn-samples,代码行数:33,代码来源:SpritesDemo.java
示例7: loadSprite
import playn.core.Image; //导入依赖的package包/类
private static void loadSprite (Platform plat, Image[] images, Sprite sprite, Json.Object json,
RPromise<Sprite> state) {
// parse image urls, if necessary
if (images == null) {
Json.Array urls = json.getArray("urls");
assert urls != null : "No urls provided for sprite images";
images = new Image[urls.length()];
for (int ii = 0; ii < urls.length(); ii++) {
images[ii] = plat.assets().getImage(urls.getString(ii));
}
}
// parse the sprite images
Json.Array spriteImages = json.getArray("sprites");
for (int i = 0; i < spriteImages.length(); i++) {
Json.Object jsonSpriteImage = spriteImages.getObject(i);
String id = jsonSpriteImage.getString("id");
int imageId = jsonSpriteImage.getInt("url"); // will return 0 if not specified
assert imageId < images.length : "URL must be an index into the URLs array";
int x = jsonSpriteImage.getInt("x");
int y = jsonSpriteImage.getInt("y");
int width = jsonSpriteImage.getInt("w");
int height = jsonSpriteImage.getInt("h");
SpriteImage spriteImage = new SpriteImage(images[imageId], x, y, width, height);
sprite.addSpriteImage(id, spriteImage);
}
// complete the sprite once the (zero or more) images have finished loading
List<RFuture<Image>> states = new ArrayList<>();
for (Image image : images) states.add(image.state);
RFuture.collect(states).map(Functions.constant(sprite)).onComplete(state.completer());
}
开发者ID:playn,项目名称:playn-samples,代码行数:33,代码来源:SpriteLoader.java
示例8: Pea
import playn.core.Image; //导入依赖的package包/类
public Pea(final GroupLayer peaLayer, float x, float y) {
Image image = plat.assets().getImage("images/pea.png");
final ImageLayer layer = new ImageLayer(image);
layer.setOrigin(ImageLayer.Origin.CENTER);
peaLayer.addAt(layer, x, y);
// connect to the paint signal to animate our rotation
paint.connect(new Slot<Clock>() {
@Override public void onEmit (Clock clock) {
layer.setRotation(clock.tick * angVel);
}
});
}
开发者ID:playn,项目名称:playn-samples,代码行数:14,代码来源:HelloGame.java
示例9: DynamicPhysicsEntity
import playn.core.Image; //导入依赖的package包/类
public DynamicPhysicsEntity(PeaWorld peaWorld, World world, Image image,
float x, float y, float angle) {
super(peaWorld, image, x, y, angle);
body = initPhysicsBody(world, x, y, angle);
setPos(x, y);
setAngle(angle);
}
开发者ID:playn,项目名称:playn-samples,代码行数:8,代码来源:DynamicPhysicsEntity.java
示例10: end
import playn.core.Image; //导入依赖的package包/类
/** Informs this layer that a drawing operation has just completed. The backing canvas image data
* is uploaded to the GPU. */
public void end () {
Texture tex = (Texture)tile();
Image image = canvas.image;
// if our texture is already the right size, just update it
if (tex != null && tex.pixelWidth == image.pixelWidth() &&
tex.pixelHeight == image.pixelHeight()) tex.update(image);
// otherwise we need to create a new texture (setTexture will unreference the old texture which
// will cause it to be destroyed)
else super.setTile(canvas.image.createTexture(Texture.Config.DEFAULT));
}
开发者ID:playn,项目名称:playn,代码行数:13,代码来源:CanvasLayer.java
示例11: getRemoteImage
import playn.core.Image; //导入依赖的package包/类
@Override public Image getRemoteImage(final String url, int width, int height) {
final JavaImage image = new JavaImage(plat, true, width, height, url);
exec.invokeAsync(new Runnable() {
public void run () {
try {
BufferedImage bmp = ImageIO.read(new URL(url));
image.succeed(new ImageImpl.Data(Scale.ONE, bmp, bmp.getWidth(), bmp.getHeight()));
} catch (Exception error) {
image.fail(error);
}
}
});
return image;
}
开发者ID:playn,项目名称:playn,代码行数:15,代码来源:JavaAssets.java
示例12: scaleImage
import playn.core.Image; //导入依赖的package包/类
protected BufferedImage scaleImage(BufferedImage image, float viewImageRatio) {
int swidth = MathUtil.iceil(viewImageRatio * image.getWidth());
int sheight = MathUtil.iceil(viewImageRatio * image.getHeight());
BufferedImage scaled = new BufferedImage(swidth, sheight, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D gfx = scaled.createGraphics();
gfx.drawImage(image.getScaledInstance(swidth, sheight, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
gfx.dispose();
return scaled;
}
开发者ID:playn,项目名称:playn,代码行数:10,代码来源:JavaAssets.java
示例13: testMissingImage
import playn.core.Image; //导入依赖的package包/类
@Test public void testMissingImage() {
final StringBuilder buf = new StringBuilder();
plat.log().setCollector(new Log.Collector() {
public void logged(Log.Level level, String msg, Throwable cause) {
buf.append(msg).append("\n");
}
});
Image missing;
try {
missing = plat.assets().getImageSync("missing.png");
} finally {
plat.log().setCollector(null);
}
assertNotNull(missing);
// ensure that width/height do not NPE
missing.width();
missing.height();
// TODO: depending on the error text is somewhat fragile, but I want to be sure that a
// reasonably appropriate error was logged
String errlog = buf.toString();
assertTrue(errlog + " must contain 'Could not load image'",
errlog.startsWith("Could not load image"));
assertTrue(errlog + " must contain 'missing.png'",
errlog.contains("missing.png"));
}
开发者ID:playn,项目名称:playn,代码行数:30,代码来源:JavaImageTest.java
示例14: getImage
import playn.core.Image; //导入依赖的package包/类
public Image getImage(ImageKey key) {
Image image = imageCache.get(key);
if (image == null) {
throw new UnsupportedOperationException("Cannot currently get images that are not cached (attempted to get " + key + ")");
}
return image;
}
开发者ID:social-startup-game,项目名称:social-startup-game,代码行数:8,代码来源:GameAssets.java
示例15: testEquals
import playn.core.Image; //导入依赖的package包/类
@Test
public void testEquals() {
EmployeeProfile profile1 = mock(EmployeeProfile.class);
Image image1 = mock(Image.class);
Employee e1 = new Employee(profile1, image1);
Employee e1Duplicate = new Employee(profile1, image1);
Employee e2 = new Employee(mock(EmployeeProfile.class), mock(Image.class));
new EqualsTester()
.addEqualityGroup(e1, e1Duplicate)
.addEqualityGroup(e2)
.testEquals();
}
开发者ID:social-startup-game,项目名称:social-startup-game,代码行数:13,代码来源:EmployeeTest.java
示例16: addRecents
import playn.core.Image; //导入依赖的package包/类
private void addRecents (Group games, Iterator<History.Game> iter) {
if (!iter.hasNext()) return;
History.Game game = iter.next();
addRecents(games, iter);
Image icon = game.icon(_game.media);
Styles color = game.loss() ? Styles.make(Style.COLOR.is(0xFF000000)) : Styles.none();
games.add((icon == null) ? new Label() : new Label(Icons.image(icon)),
new Label(String.valueOf(game.scores[0])).addStyles(color),
new Label(String.valueOf(game.scores[1])).addStyles(color));
}
开发者ID:samskivert,项目名称:mashups,代码行数:11,代码来源:HistoryScreen.java
示例17: wasAdded
import playn.core.Image; //导入依赖的package包/类
@Override public void wasAdded () {
final Root root = iface.createRoot(AxisLayout.vertical(), UI.stylesheet(game().plat), layer);
_game.media.feltTile.state.onSuccess(new Slot<Image>() {
public void onEmit (Image felt) {
root.addStyles(Style.BACKGROUND.is(Background.tiled(felt.texture()).inset(10)));
}
});
createUI(root);
root.setSize(size());
}
开发者ID:samskivert,项目名称:mashups,代码行数:11,代码来源:UIScreen.java
示例18: paint
import playn.core.Image; //导入依赖的package包/类
/**
* Interpolates between current and next coordinates (using {@code alpha} provided to prior
* call to {@link #paint(float)}) and draws all the bodies to {@code surf}.
*/
public void paint (Surface surf) {
if (_images[0] == null) return; // not yet initialized
float alpha = _alpha;
float[] data = _data;
for (int ii = 0, oo = 0, ll = count(); ii < ll; ii++, oo += FIELDS) {
float cx = data[oo+CX] + alpha * data[oo+DX];
float cy = data[oo+CY] + alpha * data[oo+DY];
Image image = _images[ii];
surf.drawImage(image, cx - image.width()/2, cy - image.height()/2);
}
}
开发者ID:playn,项目名称:playn-perf,代码行数:16,代码来源:SurfaceBodies.java
示例19: getPea
import playn.core.Image; //导入依赖的package包/类
protected Image getPea (int image, int subImage) {
Image pea = _peas[image][subImage];
if (pea == null) {
float size = _atlases[image].height();
pea = _atlases[image].subImage(size*subImage, 0, size, size);
// CanvasImage npea = graphics().createImage(size, size);
// npea.canvas().drawImage(pea, 0, 0);
// pea = npea;
_peas[image][subImage] = pea;
}
return pea;
}
开发者ID:playn,项目名称:playn-perf,代码行数:13,代码来源:BouncingQuads.java
示例20: singleImageViz
import playn.core.Image; //导入依赖的package包/类
/** All bodies use the same image for visualization. */
public static Viz singleImageViz (final Image image, final GroupLayer parent) {
return new Viz() {
public Layer createViz (int index, float x, float y) {
Layer layer = graphics().createImageLayer(image).
setOrigin(image.width()/2, image.height()/2);
parent.addAt(layer, x, y);
return layer;
}
};
}
开发者ID:playn,项目名称:playn-perf,代码行数:12,代码来源:LayerBodies.java
注:本文中的playn.core.Image类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论