/** * You can use this if you have a lot of text parameters to set instead of the individual * properties. * * @param Font The name of the font face for the text display. * @param Size The size of the font (in pixels essentially). * @param Color The color of the text in traditional flash 0xRRGGBB format. * @param Alignment A string representing the desired alignment ("left,"right" or "center"). * @param ShadowColor An int representing the desired text shadow color in flash 0xAARRGGBB * format. * @param ShadowX The x-position of the shadow, default is 1. * @param ShadowY The y-position of the shadow, default is 1. * @return This FlxText instance (nice for chaining stuff together, if you're into that). */ public FlxText setFormat( String Font, float Size, int Color, String Alignment, int ShadowColor, float ShadowX, float ShadowY) { if (Font == null) Font = _font; if (!Font.equals(_font) || Size != _size) { try { _textField = new BitmapFontCache(FlxG.loadFont(Font, FlxU.round(Size))); } catch (Exception e) { FlxG.log(e.getMessage()); _textField = new BitmapFontCache(FlxG.loadFont("org/flixel/data/font/nokiafc.fnt", 22)); } _font = Font; _size = FlxU.round(Size); } setColor(Color); if (Alignment != null) // GWT doesn't support Locale. May cause problems? _alignment = HAlignment.valueOf(Alignment.toUpperCase()); // Locale.ENGLISH)); _shadow = ShadowColor; _shadowX = ShadowX; _shadowY = ShadowY; calcFrame(); return this; }
@Override public void draw() { if (_flickerTimer != 0) { _flicker = !_flicker; if (_flicker) return; } FlxCamera camera = FlxG._activeCamera; if (cameras == null) cameras = FlxG.cameras; if (!cameras.contains(camera, true)) return; if (!onScreen(camera)) return; _point.x = x - (camera.scroll.x * scrollFactor.x) - offset.x; _point.y = y - (camera.scroll.y * scrollFactor.y) - offset.y; _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f; _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f; // scaling BitmapFont font = _textField.getFont(); if (scale.x != font.getScaleX() || scale.y != font.getScaleY()) { _textField.getFont().setScale(scale.x, scale.y); calcFrame(); } // position _textField.setPosition(_point.x, _point.y); // rotation if (angle != 0) { _matrix = FlxG.batch.getTransformMatrix().cpy(); Matrix4 rotationMatrix = FlxG.batch.getTransformMatrix(); rotationMatrix.translate( _textField.getX() + (width / 2), _textField.getY() + (height / 2), 0); rotationMatrix.rotate(0, 0, 1, angle); rotationMatrix.translate( -(_textField.getX() + (width / 2)), -(_textField.getY() + (height / 2)), 0); FlxG.batch.setTransformMatrix(rotationMatrix); } // blending if (blend != null && currentBlend != blend) { int[] blendFunc = BlendMode.getOpenGLBlendMode(blend); FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]); } else if (Gdx.graphics.isGL20Available() && (FlxG.batchShader == null || ignoreBatchShader)) { // OpenGL ES 2.0 shader render renderShader(); // OpenGL ES 2.0 blend mode render renderBlend(); } // Render shadow behind the text if (_shadow != 0) { // tinting int tintColor = FlxU.multiplyColors(_shadow, camera.getColor()); _textField.setColor( ((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, ((_shadow >> 24) & 0xFF) * _alpha * 0.00392f); _textField.translate(_shadowX, _shadowY); _textField.draw(FlxG.batch); _textField.translate(-_shadowX, -_shadowY); } // tinting int tintColor = FlxU.multiplyColors(_color, camera.getColor()); _textField.setColor( ((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, _alpha); _textField.draw(FlxG.batch); // rotation if (angle != 0) FlxG.batch.setTransformMatrix(_matrix); _VISIBLECOUNT++; if (FlxG.visualDebug && !ignoreDrawDebug) drawDebug(camera); }
/** The alignment of the font ("left", "right", or "center"). */ public void setAlignment(String Alignment) { if (Alignment == null) return; _alignment = HAlignment.valueOf(Alignment.toUpperCase()); // Locale.ENGLISH)); calcFrame(); }
/** The text being displayed. */ public void setText(CharSequence Text) { _text = Text; calcFrame(); }