List of usage examples for com.badlogic.gdx.scenes.scene2d Actor getWidth
public float getWidth()
From source file:ateamproject.kezuino.com.github.render.screens.GameScreen.java
@Override public void render(float delta) { // Render Game and UI. super.render(delta); switch (getSession().getState()) { case GameOverHighscoreReached: PacketKick packet = new PacketKick(PacketKick.KickReasonType.GAME, null, null); Client.getInstance().send(packet); game.setScreen(new HighscoreScreen(game, true)); break;// ww w .j av a2 s.c o m case GameOver: //getSession().end(); game.setScreen(new GameOverScreen(game, getSession().getScore())); break; case Completed: Actor btnContinue = new TextButton("Doorgaan", skin); Actor lblEndGameText = new Label("Je score is:", skin); Actor lblScore = new Label(Integer.toString(getSession().getScore().valueOf()), skin); btnContinue.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { btnContinue.remove(); lblEndGameText.remove(); lblScore.remove(); start(getSession().getScore()); Client.getInstance().send(new PacketLaunchGame(false, BaseScreen.getSession().getLevel() + 1, BaseScreen.getSession().getScore().valueOf(), Client.getInstance().getId())); } }); lblEndGameText.setPosition(stage.getWidth() / 2 - lblEndGameText.getWidth() / 2, stage.getHeight() - 80); lblScore.setPosition(stage.getWidth() / 2 - lblScore.getWidth() / 2, stage.getHeight() - 100); btnContinue.setSize(200, 40); btnContinue.setPosition(stage.getWidth() / 2 - btnContinue.getWidth() / 2, stage.getHeight() / 4 - btnContinue.getHeight() / 2); if (Client.getInstance().isHost()) { stage.addActor(btnContinue); } stage.addActor(lblEndGameText); stage.addActor(lblScore); getSession().end(); break; } }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private void layoutItems() { // Keep in sync with computeHeight()! float y = 0;/*from w w w . j a va 2 s. c o m*/ Menu.MenuStyle style = mMenu.getMenuStyle(); final float spacing = style.focusPadding * 2 + style.spacing; for (int idx = mItems.size - 1; idx >= 0; --idx) { MenuItem item = mItems.get(idx); ItemInfo info = mInfoForItem.get(item); if (!info.visible) { continue; } Actor actor = item.getActor(); if (actor instanceof Layout) { ((Layout) actor).invalidate(); ((Layout) actor).validate(); } float x = 0; float width = mGroup.getWidth(); if (info.label != null) { info.label.setPosition(0, y); x = mMenu.getLabelColumnWidth(); width -= x; } float ratio = mItemForActor.get(actor).getParentWidthRatio(); if (ratio > 0) { actor.setWidth(width * ratio); } if (info.label == null) { x += (width - actor.getWidth()) / 2; } actor.setPosition(x, y); y += actor.getHeight() + spacing; } }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private MenuItem getItemAt(float x, float y) { for (MenuItem item : mItems) { if (!isItemVisible(item)) { continue; }//from www .ja v a2 s . c o m Actor actor = item.getActor(); // We do not use the item focus rect because it might only represent a part of the item // For example the focus rect of a GridMenuItem is the currently selected cell of the grid mActorRectangle.set(0, 0, actor.getWidth(), actor.getHeight()); for (; actor != mGroup && actor != null; actor = actor.getParent()) { mActorRectangle.x += actor.getX(); mActorRectangle.y += actor.getY(); } if (mActorRectangle.contains(x, y)) { return item; } } return null; }
From source file:com.bagon.matchteam.mtx.scene2d.collision.CollisionDetector.java
License:Apache License
/** * Very precise point detection in an actor, think as virtual box in the * actual box with margin as precision amount * *//*from ww w .j a va 2s .co m*/ public static boolean isTouchPointCollide(float touchX, float touchY, Actor actor, float precisionAmount) { if (touchX > (actor.getX() + precisionAmount) && touchX < (actor.getX() + actor.getWidth() - precisionAmount) && touchY > (actor.getY() + precisionAmount) && touchY < (actor.getY() + actor.getHeight() - precisionAmount)) { logCollision2(actor); return true; } else { return false; } }
From source file:com.bagon.matchteam.mtx.utils.UtilsActor.java
License:Apache License
/** * Get the rectangle of an actor from its current position and size * *///w w w .j a v a 2 s . c o m public static Rectangle getRectangleOfActor(Actor actor) { return new Rectangle(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight()); }
From source file:com.bagon.matchteam.mtx.utils.UtilsOrigin.java
License:Apache License
private static void setOrigin(Actor actor, Origin origin) { switch (origin) { case CENTER:// www.jav a 2s. com actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight() / 2.0f); break; case TOP_LEFT: actor.setOrigin(0.0f, actor.getHeight()); break; case TOP_RIGHT: actor.setOrigin(actor.getWidth(), actor.getHeight()); break; case BOTTOM_LEFT: actor.setOrigin(0.0f, 0.0f); break; case BOTTOM_RIGHT: actor.setOrigin(actor.getWidth(), 0.0f); break; case LEFT_CENTER: actor.setOrigin(0.0f, actor.getHeight() / 2.0f); break; case TOP_CENTER: actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight()); break; case BOTTOM_CENTER: actor.setOrigin(actor.getWidth() / 2.0f, 0.0f); break; case RIGHT_CENTER: actor.setOrigin(actor.getWidth(), actor.getHeight() / 2.0f); break; default: actor.setOrigin(actor.getOriginX(), actor.getOriginY()); break; } }
From source file:com.bagon.matchteam.mtx.utils.UtilsPositioner.java
License:Apache License
/** * Set position of an actor due to another actor's position, , since actors * are complex objects, its variables pointing same reference with copies, * so the position will be set in original object * /*from ww w. j av a 2 s .c om*/ * * @param actorToBePositioned * actor to be positioned * @param actorStable * actor to get position data * @param position * the position to set, comes from Position enum class * */ public static void setActorPoisiton(Actor actorToBePositioned, Actor actorStable, Position position) { float atp_W = actorToBePositioned.getWidth(); float atp_H = actorToBePositioned.getHeight(); float as_X = actorStable.getX(); float as_Y = actorStable.getY(); float as_XW = actorStable.getWidth() + as_X; float as_YH = actorStable.getHeight() + as_Y; setPosition(actorToBePositioned, atp_W, atp_H, as_X, as_Y, as_XW, as_YH, position); }
From source file:com.bagon.matchteam.mtx.utils.UtilsPositioner.java
License:Apache License
/** * Set actor position in a world/screen/stage/viewport etc... * /*from w w w. ja va 2s . com*/ * @param actorToBePositioned * actor to be positioned * @param x * world x position * @param y * world y position * @param width * world width * @param height * world height * @param position * the position to set, comes from Position enum class * */ public static void setActorPoisiton(Actor actorToBePositioned, float x, float y, float width, float height, Position position) { float atp_W = actorToBePositioned.getWidth(); float atp_H = actorToBePositioned.getHeight(); float as_X = x; float as_Y = y; float as_XW = width + as_X; float as_YH = height + as_Y; setPosition(actorToBePositioned, atp_W, atp_H, as_X, as_Y, as_XW, as_YH, position); }
From source file:com.centergame.starttrack.graphics.starttrack_widgets.TeamGradeWidget.java
public void init() { setBackgroundColor(StartTrackApp.ColorPallete.BACK); setWidth(Gdx.graphics.getWidth());/* w w w .j a v a 2s . c om*/ layout.paddingLeft = mp; layout.paddingTop = mp; layout.paddingBottom = sp; layout.addActor( new Text("???? ??", StartTrackApp.getResources().getLabelStyle("header"))); if (StartTrackApp.getState().game.team_grade_required) { com.centergame.starttrack.graphics.starttrack_widgets.base.RadioGroup rg = new com.centergame.starttrack.graphics.starttrack_widgets.base.RadioGroup( 0, 3, data); rg.paddingLeft = sp / 2; rg.paddingRight = sp / 2; rg.paddingBottom = mp; rg.paddingTop = mp; rg.setWidth(getWidth() - layout.paddingLeft - layout.paddingRight); rg.layout(); layout.addActor(rg); Actor a = new IdpColorPixmap(StartTrackApp.ColorPallete.ELEMENT_BORDER).buildActor(); a.setSize(getWidth() - 2 * sp, App.dp2px(2)); Group g = new Group(); g.setWidth(getWidth() - layout.paddingLeft - layout.paddingRight); g.setHeight(a.getHeight()); g.addActor(a); a.setX(g.getWidth() / 2 - a.getWidth() / 2); layout.addActor(g); } else { Text note = new Text("? ??".toUpperCase(), StartTrackApp.getResources().getLabelStyle("number")); note.getStyle().fontColor = Color.valueOf("999999"); layout.setGap(App.dp2px(18)); note.setWidth(Gdx.graphics.getWidth() - layout.paddingRight - layout.paddingLeft); note.setAlignment(Align.center); layout.addActor(note); } Text participantsListTitle = new Text("? ??", StartTrackApp.getResources().getLabelStyle("header")); participantsListTitle.setPosition(lp, layout.getY() + layout.getHeight() + mp); layout.addActor(participantsListTitle); }
From source file:com.crashinvaders.common.scene2d.HorizontalGroupExtended.java
License:Apache License
private void computeSize() { sizeInvalid = false;//from w w w . ja v a2 s. c o m Array<Actor> children = getVisibleChildren(); int n = children.size; prefWidth = padLeft + padRight + spacing * (n - 1); prefHeight = 0; for (int i = 0; i < n; i++) { Actor child = children.get(i); if (child instanceof Layout) { Layout layout = (Layout) child; prefWidth += layout.getPrefWidth(); prefHeight = Math.max(prefHeight, layout.getPrefHeight()); } else { prefWidth += child.getWidth(); prefHeight = Math.max(prefHeight, child.getHeight()); } } prefHeight += padTop + padBottom; if (round) { prefWidth = Math.round(prefWidth); prefHeight = Math.round(prefHeight); } }