Skip to content

Instantly share code, notes, and snippets.

View PrimaryFeather's full-sized avatar

Daniel Sperl PrimaryFeather

View GitHub Profile
@PrimaryFeather
PrimaryFeather / TextureMaskStyle.as
Last active November 6, 2023 10:40
A MeshStyle for Starling 2 that discards texels with an alpha value below a certain threshold. This makes it perfect for arbitrarily shaped stencil masks.
// =================================================================================================
//
// Starling Framework
// Copyright 2011-2016 Gamua. All Rights Reserved.
//
// This program is free software. You can redistribute and/or modify it
// in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================
@PrimaryFeather
PrimaryFeather / QuadSectionArc.as
Created November 4, 2022 10:52
Starling's 'QuadSection' extension modified so that it shows just a half-circle.
package starling.extensions
{
import flash.geom.Point;
import starling.display.Mesh;
import starling.rendering.IndexData;
import starling.rendering.VertexData;
import starling.textures.Texture;
public class QuadSectionArc extends Mesh
@PrimaryFeather
PrimaryFeather / CollisionDetectionSample.as
Created February 5, 2021 07:12
Sample (for Starling Framework) showing how to detect collisions between a complex and a simple object.
package starling
{
import flash.geom.Matrix;
import flash.geom.Point;
import starling.display.Canvas;
import starling.display.Sprite;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
@PrimaryFeather
PrimaryFeather / GodRayPlane.as
Last active January 15, 2021 08:52
A Starling DisplayObject that displays animated god-rays / sunbeams within a specific area.
package starling.extensions
{
import flash.display.BitmapData;
import starling.animation.IAnimatable;
import starling.display.Quad;
import starling.textures.Texture;
import starling.utils.MathUtil;
/** A quad that efficiently renders a 2D light ray effect on its surface.
@PrimaryFeather
PrimaryFeather / MultiTextureStyle.as
Last active October 4, 2020 10:03
A "MeshStyle" for Starling that allows batching of multiple textures in one draw call.
// =================================================================================================
//
// Starling Framework
// Copyright Gamua GmbH. All Rights Reserved.
//
// This program is free software. You can redistribute and/or modify it
// in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================
@PrimaryFeather
PrimaryFeather / Gauge.as
Last active February 29, 2020 09:35
This Starling extension class displays a texture, trimmed to its left side, depending on a ratio. This can be used to create a progress bar or a rest-time display.
package starling.extensions
{
import starling.display.Image;
import starling.display.Sprite;
import starling.textures.Texture;
import starling.utils.MathUtil;
public class Gauge extends Sprite
{
private var _image:Image;
@PrimaryFeather
PrimaryFeather / ClippedSprite.as
Created April 19, 2012 17:02
Simple Sprite subclass with a rectangular mask in stage coordinates
package starling.extensions
{
import flash.display3D.Context3D;
import flash.geom.Point;
import flash.geom.Rectangle;
import starling.core.RenderSupport;
import starling.core.Starling;
import starling.display.DisplayObject;
import starling.display.Sprite;
@PrimaryFeather
PrimaryFeather / gist:5983685
Last active February 29, 2020 09:35
Water distortion filter, implemented with Starling's "DisplacementMapFilter".
private function addDistortionTo(target:DisplayObject):void
{
var offset:Number = 0;
var scale:Number = Starling.contentScaleFactor;
var width:int = target.width;
var height:int = target.height;
var perlinData:BitmapData = new BitmapData(width * scale, height * scale, false);
perlinData.perlinNoise(200*scale, 20*scale, 2, 5, true, true, 0, true);
@PrimaryFeather
PrimaryFeather / flox_dump_players.rb
Created August 1, 2019 12:12
Dumps all Flox players as JSON files to a folder.
#!/usr/bin/env ruby
require 'flox'
require 'fileutils'
GAME_ID = 'xxx'
GAME_KEY = 'yyy'
HERO_KEY = 'zzz'
OUT_FOLDER = 'flox-players'
STEP_SIZE = 50
@PrimaryFeather
PrimaryFeather / TestDeviceScaleFactors.as
Last active February 16, 2019 03:46
This code tests the logic used to come up with the stage size and content scale factor on typical devices.
package
{
import flash.display.Sprite;
public class TestDeviceScaleFactors extends Sprite
{
public function TestDeviceScaleFactors()
{
var testSettings:Array = [
{ name: "iPhone 3GS", dpi: 163, resX: 320, resY: 480 },