/** * 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; }
/** * This function creates a flat colored square image dynamically. * * @param Width The width of the sprite you want to generate. * @param Height The height of the sprite you want to generate. * @param Color Specifies the color of the generated block. * @param Unique Whether the graphic should be a unique instance in the graphics cache. Default is * false. * @param Key Optional parameter - specify a string key to identify this graphic in the cache. * Trumps Unique flag. * @return This FlxSprite instance (nice for chaining stuff together, if you're into that). */ public FlxSprite makeGraphic(int Width, int Height, int Color, boolean Unique, String Key) { _bakedRotation = 0; _pixels = FlxG.createBitmap(Width, Height, Color, Unique, Key); width = frameWidth = Width; height = frameHeight = Height; resetHelpers(); return this; }
/** * Tell the sprite to change to a specific frame of animation. * * @param Frame The frame you want to display. */ public void setFrame(int Frame) { if (Frame >= getNumFrames()) { FlxG.log( "WARNING: The frame number of a " + this + " must be less than its `numFrames` value."); Frame = getNumFrames() - 1; } _curAnim = null; _curIndex = Frame; dirty = true; }
/** * Make this <code>FlxGesture</code> object active in the manager. * * @param Callback The callback that will be fired when a gesture is performed. * @return The <code>FlxGesture</code> object that got activated. */ public FlxGesture start(IFlxGesture Callback) { GestureManager manager = getManager(); if (manager != null) manager.add(this); else { FlxG.log("WARNING: Did you forgot to plug-in GestureManager?"); return null; } _callback = Callback; return this; }
/** @private */ public void setNumFrames(int NumFrames) { if (NumFrames < 1) { FlxG.log("ERROR: Cannot set the number of frames on a " + this + " to less than 1."); _numFrames = 1; return; } if (NumFrames > _maxFrames) { FlxG.log( "ERROR: Cannot set the number of frames on a " + this + " higher than its `maxFrames` value (" + _maxFrames + ")."); _numFrames = _maxFrames; return; } // Will only re-render if the current frame number has changed if (_curIndex >= _numFrames) { _curIndex = _numFrames - 1; } }
/** * Try setting the `_curIndex` value to the specified value, extracted out to avoid duplicate * code. If it is outside of the allowed bounds, it will still set the variable to the nearest * possible value, but will return false, allowing internal code to throw its own error messages * (if necessary). Will re-draw even if the frame hasn't changed (Adam had it that way, I'll just * assume he did that on purpose). */ private boolean trySetIndex(int Value) { _curIndex = Value; dirty = true; if (_curIndex >= getNumFrames()) { _curIndex = getNumFrames(); FlxG.log( "WARNING: A " + this + " animation is trying to set the frame number of its FlxSprite out of bounds."); return false; } return true; }
/** * Load an image from an embedded graphic file. * * @param Graphic The image you want to use. * @param Animated Whether the Graphic parameter is a single sprite or a row of sprites. * @param Reverse Whether you need this class to generate horizontally flipped versions of the * animation frames. * @param Width Optional, specify the width of your sprite (helps FlxSprite figure out what to do * with non-square sprites or sprite sheets). * @param Height Optional, specify the height of your sprite (helps FlxSprite figure out what to * do with non-square sprites or sprite sheets). * @param Unique Optional, whether the graphic should be a unique instance in the graphics cache. * Default is false. * @return This FlxSprite instance (nice for chaining stuff together, if you're into that). */ public FlxSprite loadGraphic( String Graphic, boolean Animated, boolean Reverse, int Width, int Height, boolean Unique) { _bakedRotation = 0; _pixels = FlxG.addBitmap(Graphic, Reverse, Unique); if (Reverse) _flipped = _pixels.getRegionWidth() >> 1; else _flipped = 0; if (Width == 0) { if (Animated) Width = _pixels.rotate ? _pixels.getRegionWidth() : _pixels.getRegionHeight(); else Width = _pixels.rotate ? _pixels.getRegionHeight() : _pixels.getRegionWidth(); } width = frameWidth = Width; if (Height == 0) { if (Animated) Height = (int) width; else Height = _pixels.rotate ? _pixels.getRegionWidth() : _pixels.getRegionHeight(); } height = frameHeight = Height; resetHelpers(); return this; }
/** * Create a pre-rotated sprite sheet from a simple sprite. This can make a huge difference in * graphical performance! * * @param Graphic The image you want to rotate and stamp. * @param Rotations The number of rotation frames the final sprite should have. For small sprites * this can be quite a large number (360 even) without any problems. * @param Frame If the Graphic has a single row of square animation frames on it, you can specify * which of the frames you want to use here. Default is -1, or "use whole graphic." * @param AntiAliasing Whether to use high quality rotations when creating the graphic. Default is * false. * @param AutoBuffer Whether to automatically increase the image size to accommodate rotated * corners. Default is false. Will create frames that are 150% larger on each axis than the * original frame or graphic. * @return This FlxSprite instance (nice for chaining stuff together, if you're into that). */ public FlxSprite loadRotatedGraphic( String Graphic, int Rotations, int Frame, boolean AntiAliasing, boolean AutoBuffer) { _bakedRotation = 0; _pixels = FlxG.addBitmap(Graphic); if (Frame >= 0) { width = frameWidth = _pixels.getRegionHeight(); int rx = (int) (Frame * width); int ry = 0; int fw = _pixels.getRegionWidth(); if (rx >= fw) { ry = (int) ((rx / fw) * width); rx %= fw; } _pixels.setRegion( rx + _pixels.getRegionX(), ry + _pixels.getRegionY(), (int) width, (int) width); } else width = frameWidth = _pixels.getRegionWidth(); height = frameHeight = _pixels.getRegionHeight(); resetHelpers(); return this; }
/** * Plays an existing animation (e.g. "run"). If you call an animation that is already playing it * will be ignored. * * @param AnimName The string name of the animation you want to play. * @param Force Whether to force the animation to restart. * @param StartFrame Which frame of the animation to start from if possible. */ public void play(String AnimName, boolean Force, int StartFrame) { if (!Force && (_curAnim != null) && (AnimName.equals(_curAnim.name)) && (_curAnim.looped || !finished)) return; if (StartFrame <= _animations.size) _curFrame = StartFrame; else _curFrame = 0; _curIndex = 0; _frameTimer = 0; int i = 0; int l = _animations.size; while (i < l) { if (_animations.get(i).name.equals(AnimName)) { _curAnim = _animations.get(i); if (_curAnim.delay <= 0) finished = true; else finished = false; trySetIndex(_curAnim.frames.get(_curFrame)); return; } i++; } FlxG.log("FlxSprite", "WARNING: No animation called \"" + AnimName + "\""); }
/** * Get the <code>GestureManager</code> object that is used by <code>FlxGesture</code>. * * @return The <code>GestureManager</code> object. */ public static GestureManager getManager() { return (GestureManager) FlxG.getPlugin(GestureManager.class); }
public void randomize() { targetY = (int) (16 + FlxG.random() * (208 - height)); if (targetY < y) velocity.y = -SPEED; else velocity.y = SPEED; }
/** * Tell the sprite to change to a random frame of animation Useful for instantiating particles or * other weird things. */ public void randomFrame() { _curAnim = null; trySetIndex((int) (FlxG.random() * getNumFrames())); // Shouldn't ever // throw an // error. }