List of usage examples for com.badlogic.gdx.utils Array Array
public Array(T[] array)
From source file:ateamproject.kezuino.com.github.utility.game.Animation.java
public Animation(boolean hasInitialFrame, Texture frames) { TextureRegion[][] region = TextureRegion.split(frames, 32, 32); this.textures = new HashMap<>(); this.textures.put(Direction.Down, new Array<>(region[0])); this.textures.put(Direction.Right, new Array<>(region[1])); this.textures.put(Direction.Up, new Array<>(region[2])); this.textures.put(Direction.Left, new Array<>(region[3])); this.currentFrame = 0; this.hasInitialFrame = hasInitialFrame; }
From source file:by.aleks.christmasboard.data.BitmapFontWriter.java
License:Apache License
/** Writes the given BitmapFontData to a file, using the specified <tt>pageRefs</tt> strings as the image paths for each texture * page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. * // ww w .ja v a2 s . c om * The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be * null to use default values. Ultimately, LibGDX ignores the "info" line when reading back fonts. * * Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by LibGDX's reader. For maximum * compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the * same size). * * @param fontData the bitmap font * @param pageRefs the references to each texture page image file, generally in the same folder as outFntFile * @param outFntFile the font file to save to (typically ends with '.fnt') * @param info the optional info for the file header; can be null * @param scaleW the width of your texture pages * @param scaleH the height of your texture pages */ public static void writeFont(BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, FontInfo info, int scaleW, int scaleH) { if (info == null) { info = new FontInfo(); info.face = outFntFile.nameWithoutExtension(); } int lineHeight = (int) fontData.lineHeight; int pages = pageRefs.length; int packed = 0; int base = (int) ((fontData.capHeight) + (fontData.flipped ? -fontData.ascent : fontData.ascent)); OutputFormat fmt = BitmapFontWriter.getOutputFormat(); boolean xml = fmt == OutputFormat.XML; StringBuilder buf = new StringBuilder(); if (xml) { buf.append("<font>\n"); } String xmlOpen = xml ? "\t<" : ""; String xmlCloseSelf = xml ? "/>" : ""; String xmlTab = xml ? "\t" : ""; String xmlClose = xml ? ">" : ""; String xmlQuote = xml ? "\"" : ""; String alphaChnlParams = xml ? " alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"" : " alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0"; //INFO LINE buf.append(xmlOpen).append("info face=\"").append(info.face == null ? "" : info.face.replaceAll("\"", "'")) .append("\" size=").append(quote(info.size)).append(" bold=").append(quote(info.bold ? 1 : 0)) .append(" italic=").append(quote(info.italic ? 1 : 0)).append(" charset=\"") .append(info.charset == null ? "" : info.charset).append("\" unicode=") .append(quote(info.unicode ? 1 : 0)).append(" stretchH=").append(quote(info.stretchH)) .append(" smooth=").append(quote(info.smooth ? 1 : 0)).append(" aa=").append(quote(info.aa)) .append(" padding=").append(xmlQuote).append(info.padding.up).append(",").append(info.padding.down) .append(",").append(info.padding.left).append(",").append(info.padding.right).append(xmlQuote) .append(" spacing=").append(xmlQuote).append(info.spacing.horizontal).append(",") .append(info.spacing.vertical).append(xmlQuote).append(xmlCloseSelf).append("\n"); //COMMON line buf.append(xmlOpen).append("common lineHeight=").append(quote(lineHeight)).append(" base=") .append(quote(base)).append(" scaleW=").append(quote(scaleW)).append(" scaleH=") .append(quote(scaleH)).append(" pages=").append(quote(pages)).append(" packed=") .append(quote(packed)).append(alphaChnlParams).append(xmlCloseSelf).append("\n"); if (xml) buf.append("\t<pages>\n"); //PAGES for (int i = 0; i < pageRefs.length; i++) { buf.append(xmlTab).append(xmlOpen).append("page id=").append(quote(i)).append(" file=\"") .append(pageRefs[i]).append("\"").append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</pages>\n"); //CHARS Array<Glyph> glyphs = new Array<Glyph>(256); for (int i = 0; i < fontData.glyphs.length; i++) { if (fontData.glyphs[i] == null) continue; for (int j = 0; j < fontData.glyphs[i].length; j++) { if (fontData.glyphs[i][j] != null) { glyphs.add(fontData.glyphs[i][j]); } } } buf.append(xmlOpen).append("chars count=").append(quote(glyphs.size)).append(xmlClose).append("\n"); //CHAR definitions for (int i = 0; i < glyphs.size; i++) { Glyph g = glyphs.get(i); buf.append(xmlTab).append(xmlOpen).append("char id=").append(quote(String.format("%-5s", g.id), true)) .append("x=").append(quote(String.format("%-5s", g.srcX), true)).append("y=") .append(quote(String.format("%-5s", g.srcY), true)).append("width=") .append(quote(String.format("%-5s", g.width), true)).append("height=") .append(quote(String.format("%-5s", g.height), true)).append("xoffset=") .append(quote(String.format("%-5s", g.xoffset), true)).append("yoffset=") .append(quote(String.format("%-5s", fontData.flipped ? g.yoffset : -(g.height + g.yoffset)), true)) .append("xadvance=").append(quote(String.format("%-5s", g.xadvance), true)).append("page=") .append(quote(String.format("%-5s", g.page), true)).append("chnl=").append(quote(0, true)) .append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</chars>\n"); //KERNINGS int kernCount = 0; StringBuilder kernBuf = new StringBuilder(); for (int i = 0; i < glyphs.size; i++) { for (int j = 0; j < glyphs.size; j++) { Glyph first = glyphs.get(i); Glyph second = glyphs.get(j); int kern = first.getKerning((char) second.id); if (kern != 0) { kernCount++; kernBuf.append(xmlTab).append(xmlOpen).append("kerning first=").append(quote(first.id)) .append(" second=").append(quote(second.id)).append(" amount=") .append(quote(kern, true)).append(xmlCloseSelf).append("\n"); } } } //KERN info buf.append(xmlOpen).append("kernings count=").append(quote(kernCount)).append(xmlClose).append("\n"); buf.append(kernBuf); if (xml) { buf.append("\t</kernings>\n"); buf.append("</font>"); } String charset = info.charset; if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset); }
From source file:cocos2d.sprite_nodes.CCAnimation.java
License:Open Source License
public boolean initWithAnimationFrames(Array<CCAnimationFrame> arrayOfAnimationFrames, float delayPerUnit, int loops) { if (arrayOfAnimationFrames != null) {/* foreach (object frame in arrayOfAnimationFrames) { Debug.Assert(frame is CCAnimationFrame, "element type is wrong!"); } */ }//ww w . j a v a 2 s . c om m_fDelayPerUnit = delayPerUnit; m_uLoops = loops; m_pFrames = new Array<CCAnimationFrame>(arrayOfAnimationFrames); for (CCAnimationFrame pObj : m_pFrames) { CCAnimationFrame animFrame = (CCAnimationFrame) pObj; m_fTotalDelayUnits += animFrame.getDelayUnits(); } return true; }
From source file:cocos2d.touch_dispatcher.CCTouchDispatcher.java
License:Open Source License
public void touches(Array<CCTouch> pTouches, CCTouchType touchType) { m_bLocked = true;/*from ww w . j a v a 2 s . co m*/ // optimization to prevent a mutable copy when it is not necessary int uTargetedHandlersCount = m_pTargetedHandlers.size; int uStandardHandlersCount = m_pStandardHandlers.size; boolean bNeedsMutableSet = (uTargetedHandlersCount > 0 && uStandardHandlersCount > 0); if (bNeedsMutableSet) { CCTouch[] tempArray = new CCTouch[pTouches.size]; tempArray = pTouches.toArray(); //Collections.addAll(pMutableTouches, tempArray); pMutableTouches = new Array<CCTouch>(tempArray); } else { pMutableTouches = pTouches; } CCTouchType sHelper = touchType; // process the target handlers 1st if (uTargetedHandlersCount > 0) { for (CCTouch pTouch : pTouches) { for (CCTouchHandler pcHandler : m_pTargetedHandlers) { CCTargetedTouchHandler pHandler = (CCTargetedTouchHandler) pcHandler; ICCTargetedTouchDelegate pDelegate = (ICCTargetedTouchDelegate) (pHandler.getDelegate()); boolean bClaimed = false; if (sHelper == CCTouchType.Began) { bClaimed = pDelegate.touchBegan(pTouch); if (bClaimed) { pHandler.getClaimedTouches().add(pTouch); } } else { if (pHandler.getClaimedTouches().contains(pTouch)) { // moved ended cancelled bClaimed = true; switch (sHelper) { case Moved: pDelegate.touchMoved(pTouch); break; case Ended: pDelegate.touchEnded(pTouch); pHandler.getClaimedTouches().remove(pTouch); break; case Cancelled: pDelegate.touchCancelled(pTouch); pHandler.getClaimedTouches().remove(pTouch); break; } } } if (bClaimed && pHandler.getIsSwallowsTouches()) { if (bNeedsMutableSet) { pMutableTouches.removeValue(pTouch, true); } break; } } } } // process standard handlers 2nd if (uStandardHandlersCount > 0 && pMutableTouches.size > 0) { for (CCTouchHandler pcHandler : m_pStandardHandlers) { CCStandardTouchHandler pHandler = (CCStandardTouchHandler) pcHandler; ICCStandardTouchDelegate pDelegate = (ICCStandardTouchDelegate) pHandler.getDelegate(); switch (sHelper) { case Began: pDelegate.touchesBegan(pMutableTouches); break; case Moved: pDelegate.touchesMoved(pMutableTouches); break; case Ended: pDelegate.touchesEnded(pMutableTouches); break; case Cancelled: pDelegate.touchesCancelled(pMutableTouches); break; } } } if (bNeedsMutableSet) { pMutableTouches = null; } // // Optimization. To prevent a [handlers copy] which is expensive // the add/removes/quit is done after the iterations // m_bLocked = false; if (m_bToRemove) { m_bToRemove = false; for (int i = 0; i < m_pHandlersToRemove.size; ++i) { forceRemoveDelegate((ICCTouchDelegate) m_pHandlersToRemove.get(i)); } m_pHandlersToRemove.clear(); } if (m_bToAdd) { m_bToAdd = false; for (CCTouchHandler pHandler : m_pHandlersToAdd) { if (pHandler instanceof CCTargetedTouchHandler && pHandler.getDelegate() instanceof ICCTargetedTouchDelegate) { forceAddHandler(pHandler, m_pTargetedHandlers); } else if (pHandler instanceof CCStandardTouchHandler && pHandler.getDelegate() instanceof ICCStandardTouchDelegate) { forceAddHandler(pHandler, m_pStandardHandlers); } else { //CCLog.Log("ERROR: inconsistent touch handler and delegate found in m_pHandlersToAdd of CCTouchDispatcher"); } } m_pHandlersToAdd.clear(); } if (m_bToQuit) { m_bToQuit = false; forceRemoveAllDelegates(); } // for (CCTouchHandler pHandler : m_pTargetedHandlers) // { // ICCTargetedTouchDelegate pDelegate = (ICCTargetedTouchDelegate)pHandler.getDelegate(); // pDelegate.touchBegan(pTouches.get(0)); // } }
From source file:com.agateau.pixelwheels.gameinput.GameInputHandlerFactories.java
License:Open Source License
public static Map<String, Array<GameInputHandler>> getInputHandlersByIds() { init();//from w w w . j av a2 s . c o m Map<String, Array<GameInputHandler>> map = new HashMap<String, Array<GameInputHandler>>(); for (GameInputHandlerFactory factory : mFactories) { map.put(factory.getId(), new Array<GameInputHandler>(factory.getAllHandlers())); } return map; }
From source file:com.ahsgaming.superrummy.GameController.java
License:Apache License
/** * Constructors/*from w ww .j av a 2s .c o m*/ */ public GameController(Array<Player> players) { deck = new CardStack(null); deck.setHidden(true); deck.setCompressed(true); discards = new CardStack(null); discards.setHidden(false); discards.setCompressed(true); this.players = players; melds = new Array<Meld>(players.size * 3); }
From source file:com.ahsgaming.superrummy.GameController.java
License:Apache License
public void meld(Player p) { if (!isCurrentPlayer(p) || !hasDrawn) return;/*from ww w .ja v a 2s .c om*/ Array<Card> selected = new Array<Card>(p.getHand().getCards().size); for (Card c : p.getHand().getCards()) { if (c.isSelected()) selected.add(new Card(c.getValue(), c.getSuit())); } Book b = new Book(Utils.getRandomId(), p); b.addAll(selected); if (b.isValid()) { // yay we can meld a book b = new Book(Utils.getRandomId(), p); for (Card c : p.getHand().getCards()) { if (c.isSelected()) b.addCard(c); } doMeld(p, b); return; } // TODO add runs Run r = new Run(Utils.getRandomId(), p); r.addAll(selected); if (r.isValid()) { r = new Run(Utils.getRandomId(), p); for (Card c : p.getHand().getCards()) { if (c.isSelected()) r.addCard(c); } doMeld(p, b); return; } // TODO need to implement a 'meld mode' since we can only meld if we have all the melds demanded }
From source file:com.andgate.pokeadot.GameScreen.java
License:Open Source License
private void buildPauseButtonScene() { pauseButtonStage = new Stage(); //pauseButtonStage.getViewport().setCamera(camera); ImageButton pauseButton = game.createIconButton(Constants.PAUSE_ICON_LOCATION, Constants.PAUSE_ICON_DOWN_LOCATION, new ClickListener() { @Override/*from w ww. j a va 2 s .c o m*/ public void clicked(InputEvent event, float x, float y) { gameState = GameState.PAUSE; game.buttonPressedSound.play(); im.setProcessors(new Array<InputProcessor>( new InputProcessor[] { pauseMenuStage, new GameInputProcessor() })); } }); Table table = new Table(game.skin); table.bottom().left(); table.add(pauseButton).bottom().left(); table.setFillParent(true); pauseButtonStage.addActor(table); }
From source file:com.andgate.pokeadot.GameScreen.java
License:Open Source License
private void buildPauseMenuScene() { pauseMenuStage = new Stage(); //pauseMenuStage.getViewport().setCamera(camera); ImageButton playButtonWrapper = game.createIconButton(Constants.PLAY_ICON_LOCATION, Constants.PLAY_ICON_DOWN_LOCATION, new ClickListener() { @Override/* www. j a v a 2 s . c om*/ public void clicked(InputEvent event, float x, float y) { gameState = GameState.RUN; game.buttonPressedSound.play(); im.setProcessors(new Array<InputProcessor>( new InputProcessor[] { pauseButtonStage, new GameInputProcessor() })); } }); ImageButton stopButtonWrapper = game.createIconButton(Constants.STOP_ICON_LOCATION, Constants.STOP_ICON_DOWN_LOCATION, new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.buttonPressedSound.play(); gameState = GameState.OVER; } }); final Label.LabelStyle pauseLabelStyle = new Label.LabelStyle(game.largeFont, new Color(1.0f, 1.0f, 1.0f, 0.7f)); final Label pauseLabel = new Label(PAUSE_TEXT, pauseLabelStyle); Table buttonTable = new Table(); buttonTable.add(playButtonWrapper).left(); buttonTable.add(stopButtonWrapper).expandX().right(); Table table = new Table(game.skin); table.add(pauseLabel).center().spaceBottom(25.0f).row(); table.add(buttonTable).fill(); table.setFillParent(true); pauseMenuStage.addActor(table); }
From source file:com.andgate.pokeadot.GameScreen.java
License:Open Source License
private void updateIntro() { update(0.0f);/* w ww . j a v a 2 s . co m*/ if (Gdx.input.isTouched()) { gameState = GameState.RUN; im.setProcessors( new Array<InputProcessor>(new InputProcessor[] { pauseButtonStage, new GameInputProcessor() })); } }