@Override protected void makeComplete () { _layer.setTranslation(_startX, _startY); }
public void set (float x, float y) { layer.setTranslation(x, y); } };
/** * Adds the supplied layer to this group layer, adjusting its translation (relative to this group * layer) to the supplied values. * * <p>This is equivalent to: {@code add(child.setTranslation(tx, ty))}. */ public void addAt(Layer child, float tx, float ty) { add(child.setTranslation(tx, ty)); }
protected void doMove(float x, float y) { Vector delta = new Vector(x, y).subtractLocal(_pstart); layer.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y); }
/** * A variant of {@link #setTranslation(float,float)} that takes an {@code XY}. */ public Layer setTranslation(XY trans) { return setTranslation(trans.x(), trans.y()); }
@Override protected float apply (float time) { float dt = time-_start, nx, ny; if (dt < _duration) { float dtx = time-_timeX, dty = time-_timeY; if (dtx < _cycleTimeX) nx = _interp.apply(_curMinX, _curRangeX, dtx, _cycleTimeX); else { nx = _curMinX + _curRangeX; _curMinX = nx; float rangeX = _startX + (_curRangeX < 0 ? _overX : _underX) - nx; _curRangeX = rangeX/2 + RANDS.nextFloat() * rangeX/2; _timeX = time; } if (dty < _cycleTimeY) ny = _interp.apply(_curMinY, _curRangeY, dty, _cycleTimeY); else { ny = _curMinY + _curRangeY; _curMinY = ny; float rangeY = _startY + (_curRangeY < 0 ? _overY : _underY) - ny; _curRangeY = rangeY/2 + RANDS.nextFloat() * rangeY/2; _timeY = time; } } else { nx = _startX; ny = _startY; } _layer.setTranslation(nx, ny); return _duration - dt; }
/** * Adds {@code child} to this group layer, positioning it such that its center is at ({@code tx}, * {@code tx}). The layer must report a non-zero size, thus this will not work on an unclipped * group layer. * * <p>This is equivalent to: {@code add(child.setTranslation(tx - child.width()/2, * ty - child.height()/2))}. */ public void addCenterAt (Layer child, float tx, float ty) { add(child.setTranslation(tx - child.width()/2, ty - child.height()/2)); }
/** * Adds {@code child} to this group layer, adjusting its translation (relative to this group * layer) to {@code floor(tx), floor(ty)}. This is useful for adding layers which display text a * text can become blurry if it is positioned on sub-pixel boundaries. */ public void addFloorAt (Layer child, float tx, float ty) { add(child.setTranslation(MathUtil.ifloor(tx), MathUtil.ifloor(ty))); }
protected void updateThumb () { // bail if not laid out yet, we'll get called again layer if (_thumb == null) return; Range r = range.get(); float thumbPct = (value.get() - r.min) / r.range; float thumbOffset = _thumbRange * thumbPct; _thumb.setTranslation(_thumbLeft + thumbOffset, _thumbY); if (_barOnLayer != null) { _barOnLayer.setWidth(thumbOffset); } }
@Override public void onEmit () { float tx = 100 + rando.getFloat(size().width()-200); float ty = 100 + rando.getFloat(size().height()-200); explode1.layer.setTranslation(tx, ty); explode2.layer.setTranslation(tx, ty); explode1.generator = Generator.impulse(200); explode2.generator = Generator.impulse(200); }}); }
@Override protected void layout (LayoutData ldata, float left, float top, float width, float height) { // set the bars and element buffer first so the ScrollLayout can use them _elementBuffer = resolveStyle(ELEMENT_BUFFER); updateBars(((BarsLayoutData)ldata).barType); super.layout(ldata, left, top, width, height); if (_bars != null) layer.add(_bars.layer().setDepth(1).setTranslation(left, top)); }
@Override protected void createParticles (ParticleBatch batch, Randoms rando) { Canvas image = graphics().createCanvas(7, 7); image.setFillColor(0xFFFFFFFF); image.fillCircle(3, 3, 3); Tile tile = image.toTexture(); Emitter emitter = new Emitter(batch, paint, 5000, tile); emitter.generator = Generator.constant(100); emitter.initters.add(Lifespan.constant(5)); emitter.initters.add(Color.constant(0xFF99CCFF)); emitter.initters.add(Transform.layer(emitter.layer)); emitter.initters.add(Velocity.randomSquare(rando, -20, 20, -100, 0)); emitter.effectors.add(new Gravity(30)); emitter.effectors.add(new Move()); emitter.effectors.add(Alpha.byAge(Interpolator.EASE_OUT, 1, 0)); emitter.layer.setTranslation(size().width()/2, size().height()/2); add(emitter); } }
@Override protected void paint (Clock clock, Entities entities) { float alpha = clock.alpha; Point op = _oldPos, p = _pos; for (int ii = 0, ll = entities.size(); ii < ll; ii++) { int eid = entities.get(ii); // interpolate between opos and pos and use that to update the sprite position opos.get(eid, op); pos.get(eid, p); // wrap our interpolated position as we may interpolate off the screen sprite.get(eid).setTranslation(wrapx(MathUtil.lerp(op.x, p.x, alpha)), wrapy(MathUtil.lerp(op.y, p.y, alpha))); } }
/** * Removes {@code layer} from its current parent and adds it to {@code target}, modifying its * transform in the process so that it stays in the same position on the screen. */ public static void reparent (Layer layer, GroupLayer target) { Point pos = new Point(layer.tx(), layer.ty()); LayerUtil.layerToScreen(layer.parent(), pos, pos); target.add(layer); LayerUtil.screenToLayer(layer.parent(), pos, pos); layer.setTranslation(pos.x, pos.y); }
@Override public void init() { int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 }; int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033, 0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 }; int width = 200, height = 200; for (int ii = 0; ii < depths.length; ii++) { int depth = depths[ii]; Canvas canvas = game.graphics.createCanvas(width, height); canvas.setFillColor(fills[ii]).fillRect(0, 0, width, height); canvas.setFillColor(0xFF000000).drawText(depth + "/" + ii, 5, 15); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setDepth(depth).setTranslation(225-50*depth, 125+25*depth); game.rootLayer.add(layer); } } }
@Override protected void createParticles (ParticleBatch batch, final Randoms rando) { Canvas image = graphics().createCanvas(2, 2); image.setFillColor(0xFFFFFFFF).fillRect(0, 0, 2, 2); Tile tile = image.toTexture(); final Emitter explode1 = createEmitter(batch, rando, tile, 0xFFFFCD82, 0.975f); final Emitter explode2 = createEmitter(batch, rando, tile, 0xFFF06969, 0.95f); add(explode1); add(explode2); float tx = 100 + rando.getFloat(size().width()-200); float ty = 100 + rando.getFloat(size().height()-200); explode1.layer.setTranslation(tx, ty); explode2.layer.setTranslation(tx, ty); explode1.onEmpty.connect(new UnitSlot() { @Override public void onEmit () { float tx = 100 + rando.getFloat(size().width()-200); float ty = 100 + rando.getFloat(size().height()-200); explode1.layer.setTranslation(tx, ty); explode2.layer.setTranslation(tx, ty); explode1.generator = Generator.impulse(200); explode2.generator = Generator.impulse(200); }}); }
@Override public void init () { Canvas bgcanvas = game.graphics.createCanvas(WIDTH + 10, HEIGHT); bgcanvas.setFillColor(0xff808080); bgcanvas.fillRect(0, 0, WIDTH + 10, HEIGHT); ImageLayer bg = new ImageLayer(bgcanvas.toTexture()); Canvas knob = game.graphics.createCanvas(WIDTH, HWIDTH); knob.setFillColor(0xffffffff).fillRect(0, 0, WIDTH, HWIDTH); knob.setStrokeColor(0xff000000).drawLine(0, HWIDTH / 2, WIDTH, HWIDTH / 2); knob.setStrokeColor(0xffff0000).strokeRect(0, 0, WIDTH - 1, HWIDTH - 1); ImageLayer il = new ImageLayer(knob.toTexture()); il.setOrigin(0, HWIDTH / 2).setDepth(1).setTranslation(0, HEIGHT / 2); GroupLayer slider = new GroupLayer(); slider.add(bg); slider.add(il); game.rootLayer.addAt(slider, 25, 25); bg.events().connect(new Mouse.Listener() { @Override public void onWheel (Mouse.WheelEvent event, Mouse.Interaction iact) { float y = il.ty() + event.velocity; y = Math.max(0, Math.min(y, HEIGHT)); il.setTranslation(0, y); } }); } }