private void DrawOffscreen(int x, int y) { var demo = (DemoReel)RB.Game; Vector2i textSize = RB.PrintMeasure(mText); RB.Offscreen(2); RB.Clear(new Color32(0, 0, 0, 0)); RB.DrawNineSlice(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(80, 0, 8, 8), new Rect2i(88, 0, 8, 8), new Rect2i(96, 0, 16, 16)); RB.Print(new Vector2i(6, 6), DemoUtil.IndexToRGB(23), mText); RB.Onscreen(); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(x, y + 165, textSize.width + 12, textSize.height + 12), new Vector2i((textSize.width + 12) / 2, (textSize.height + 12) / 2), RB.Ticks); RB.SpriteSheetSet(0); mFormatStr.Set("@C// Draw to offscreen surface and copy to screen\n"); mFormatStr.Append("@MVector2i @Nsize = @[email protected](textStr);\n"); mFormatStr.Append("@[email protected](0);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N, size.width + @L12@N, size.height + @L12@N),\n"); mFormatStr.Append(" @Knew @MRect2i@N(@L80@N, @L0@N, @L8@N, @L8@N), @Knew @MRect2i@N(@L88@N, @L0@N, @L8@N, @L8@N),\n"); mFormatStr.Append(" @Knew @MRect2i@N(@L96@N, @L0@N, @L16@N, @L16@N));\n"); mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L4@N, @L4@N), @I22@N, textStr);\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](0, \n"); mFormatStr.Append(" @Knew@M Rect2i@N(@L0@N, @L0@N, size.width + @L7@N, size.height + @L8@N),\n"); mFormatStr.Append(" @Knew@M Rect2i@N(@L").Append(x).Append("@N, @L").Append(y + 165).Append("@N, size.width + @L8@N, size.height + @L8@N),\n"); mFormatStr.Append(" @Knew@M Vector2i@N(size.width / @L2@N, size.height / @L2@N), @L").Append(RB.Ticks % 360).Append("@N);\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawTilemap(int x, int y) { var demo = (DemoReel)RB.Game; RB.Offscreen(spriteSheet1); RB.SpriteSheetSet(spriteSheet2); mWaveOffset = (int)((RB.Ticks / 2) % 16); mFishFrame = (int)((RB.Ticks / 6) % 32); RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSheetGet().grid.cellSize), new Vector2i(48, 192)); RB.Clear(new Color32(0, 0, 0, 0), new Rect2i(80, 192, RB.SpriteSheetGet().grid.cellSize)); if (mFishFrame < 7) { RB.DrawCopy(new Rect2i(mFishFrame * RB.SpriteSheetGet().grid.cellSize.width, RB.SpriteSheetGet().grid.cellSize.height, RB.SpriteSheetGet().grid.cellSize), new Vector2i(80, 192)); } RB.Onscreen(); Rect2i clipRect = new Rect2i(x, y + (RB.DisplaySize.height / 2) - 8, 632, 180); if (mMap != null) { RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(new Vector2i(0, 0)); RB.DrawMapLayer(2); RB.DrawMapLayer(3); RB.TintColorSet(Color.black); RB.AlphaSet(32); int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width); RB.DrawMapLayer(1, new Vector2i(scrollPos + 8, 8)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width) + 8, 8)); RB.TintColorSet(Color.white); RB.AlphaSet(196); RB.DrawMapLayer(1, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width), 0)); RB.AlphaSet(255); RB.CameraReset(); RB.ClipReset(); RB.SpriteSheetSet(spriteSheet1); } else { RB.Print(new Vector2i(clipRect.x + 2, clipRect.y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapOcean.tmx in Unity"); } RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); }
/// <summary> /// Run the stress test /// </summary> protected override void StressTest() { Random.InitState(0); RB.Offscreen(3); RB.Clear(new Color32(0, 0, 0, 0)); RB.Offscreen(2); RB.Clear(new Color32(0, 0, 0, 0)); // Generate texture on first offscreen surface for (int i = 0; i < 64; i++) { int radius = Random.Range(2, 5); RB.DrawEllipseFill( new Vector2i(Random.Range(-4, 36), Random.Range(-4, 36)), new Vector2i(radius, radius), mRandomColor[i]); } // Copy the generate texture mirrored on second offscreen surface RB.Offscreen(3); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, 32, 32), Vector2i.zero, RB.FLIP_H | RB.FLIP_V); RB.Onscreen(); for (int i = 0; i < mStressLevel; i++) { var randPos = mRandomPos[i]; randPos += GetWiggle(); // Draw half the sprites from offscreen 0 and half from 1. int offscreen = 2; if (i >= mStressLevel / 2) { offscreen = 3; } RB.SpriteSheetSet(offscreen); RB.DrawCopy(new Rect2i(0, 0, 32, 32), randPos); } }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; if (mMap != null) { RB.Offscreen(2); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), DemoUtil.IndexToRGB(22)); RB.DrawMapLayer(0); RB.DrawMapLayer(1); RB.Offscreen(3); RB.Clear(new Color32(0, 0, 0, 0)); RB.SpriteSheetSet(1); RB.DrawSprite(0, new Vector2i((int)mBouncePos.x, (int)mBouncePos.y), mVelocity.x > 0 ? RB.FLIP_H : 0); RB.Onscreen(); RB.ShaderSet(0); RB.ShaderSpriteSheetTextureSet(0, "Mask", 3); RB.ShaderFloatSet(0, "Wave", RB.Ticks / 10.0f); RB.ShaderSpriteSheetFilterSet(0, 3, RB.Filter.Linear); RB.SpriteSheetSet(2); RB.DrawCopy(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), Vector2i.zero); RB.ShaderReset(); RB.SpriteSheetSet(0); } else { RB.Print(new Vector2i(x, y + 250), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } string shaderName = "WavyMaskShader"; mFormatStr.Set("@C// Custom shaders can be used for many things, like masking!\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Demos/DemoReel/").Append(shaderName).Append("\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a tilemap to one offscreen surface\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n"); mFormatStr.Append(" @[email protected], @[email protected]),\n"); mFormatStr.Append(" @I22@N);\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a mask to the other offscreen surface\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("@[email protected](@Knew @MColor32@N(@L0@N, @L0@N, @L0@N, @L0@N));\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew @MVector2i@N(@L").Append((int)mBouncePos.x).Append("@N, @L").Append((int)mBouncePos.y).Append("@N)").Append(mVelocity.x > 0 ? ", RB.FLIP_H" : string.Empty).Append(");\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Use a custom shader to combine the two!\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Mask\"@N, @L1@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @S\"Wave\"@N, @L").Append(RB.Ticks / 10.0f, 2).Append("f@N);\n"); mFormatStr.Append("@[email protected](@L0@N, @L3@N, @MRB@N.@[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n @[email protected], @[email protected]),\n @[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\n"); DemoUtil.HighlightCode(mFormatStr, mCodeStr); mFormatStr.Set("@C// This shader multiplies in a mask and applies a wavy effect!\n"); mFormatStr.Append("@KShader@N \"Unlit/").Append(shaderName).Append("\" {\n"); mFormatStr.Append(" @KSubShader@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @KPass@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom shader variables here ***/\n"); mFormatStr.Append(" @Ksampler2D@N Mask;\n"); mFormatStr.Append(" @Kfloat@N Wave;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Nfrag_in vert(vert_in v, @Kout float4@N screen_pos : @MSV_POSITION@N) {\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kfloat4@N frag(frag_in i, @MUNITY_VPOS_TYPE@N screen_pos : @MVPOS@N) : @MSV_Target@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom fragment shader code here ***/@N\n"); mFormatStr.Append(" @C// Sample the mask texture@N\n"); mFormatStr.Append(" i.uv.x += sin(Wave + i.uv.y * @L8@N) * @L0.025@N;\n"); mFormatStr.Append(" i.uv.y += cos(Wave - i.uv.x * @L8@N) * @L0.015@N;\n"); mFormatStr.Append(" @Kfloat4@N mask_color = @Mtex2D@N(Mask, i.uv).rgba;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @C// Multiply the sprite pixel by mask color@N\n"); mFormatStr.Append(" @Kreturn@N sprite_pixel_color * mask_color;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); DemoUtil.HighlightCode(mFormatStr, mShaderStr); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), mCodeStr); RB.Print(new Vector2i(x + 300, y), DemoUtil.IndexToRGB(5), mShaderStr); }
private void DrawAll(int x, int y) { var demo = (DemoReel)RB.Game; var gridColor = DemoUtil.IndexToRGB(14); RB.Offscreen(0); RB.SpriteSheetSet(1); mWaveOffset = (int)((RB.Ticks / 2) % 8); RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSize()), new Vector2i(24, 8)); RB.Onscreen(); Rect2i clipRectOverlap = mClipRect; clipRectOverlap.width += 400; if (mMap != null) { RB.DrawRectFill(mClipRect, DemoUtil.IndexToRGB(22)); } RB.ClipSet(clipRectOverlap); DrawTilemap(mClipRect.x, mClipRect.y); RB.ClipReset(); RB.CameraReset(); // Blank out right side RB.AlphaSet(196); RB.DrawRectFill(new Rect2i(mClipRect.x + mClipRect.width, mClipRect.y, 300, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.AlphaSet(255); // Blank out left side RB.DrawRectFill(new Rect2i(0, mClipRect.y, mClipRect.x - 1, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.DrawRect(mClipRect, DemoUtil.IndexToRGB(7)); if (mMap == null) { return; } RB.AlphaSet(128); mFinalStr.Set("Chunk Tile Offset:"); RB.Print(new Vector2i(mClipRect.x, mClipRect.y - 16), gridColor, mFinalStr); RB.CameraSet(mChunkCameraPos - new Vector2i(mClipRect)); int gxStart = 0; int gxEnd = gxStart + (RB.DisplaySize.width * 2); for (int gx = gxStart; gx < gxEnd; gx += RB.MapChunkSize.width * RB.SpriteSize().x) { RB.DrawLine(new Vector2i(gx, -8), new Vector2i(gx, mClipRect.height + 4), gridColor); mFinalStr.Set(gx / RB.SpriteSize().x); RB.Print(new Vector2i(gx + 3, -8), gridColor, mFinalStr); } RB.AlphaSet(255); RB.CameraReset(); RB.SpriteSheetSet(0); }
private void DrawMusicPlayer(int x, int y) { var demo = (DemoReel)RB.Game; RB.Offscreen(mSpriteSheet2); RB.Clear(new Color32(0, 0, 0, 0)); int spinnerSize = 32; RB.DrawRectFill(new Rect2i(spinnerSize / 4, spinnerSize - 2, (spinnerSize / 2) - 2, 5), DemoUtil.IndexToRGB(1)); RB.DrawRectFill(new Rect2i(spinnerSize + (spinnerSize / 4) + 3, spinnerSize - 2, (spinnerSize / 2) - 2, 5), DemoUtil.IndexToRGB(1)); RB.DrawRectFill(new Rect2i(spinnerSize - 2, spinnerSize / 4, 5, (spinnerSize / 2) - 2), DemoUtil.IndexToRGB(1)); RB.DrawRectFill(new Rect2i(spinnerSize - 2, spinnerSize + (spinnerSize / 4) + 3, 5, (spinnerSize / 2) - 2), DemoUtil.IndexToRGB(1)); RB.Onscreen(); RB.CameraSet(new Vector2i(-x, -y)); mFormatStr.Set("@C// Load music and play it\n"); mFormatStr.Append("@NdemoMusic.Load(@S\"Demos/Demo/Music\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@Kif@N (@[email protected](@[email protected]) {\n"); mFormatStr.Append(" @[email protected](demoMusic);\n"); mFormatStr.Append("} @Kelse if@N (@[email protected](@[email protected]) {\n"); mFormatStr.Append(" @[email protected]();\n"); mFormatStr.Append("}"); RB.Print(new Vector2i(0, 0), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); RB.CameraSet(new Vector2i(-x, -y - 80)); int cornerSize = 8; var deckRect = new Rect2i(20, 40, 145, 100); RB.DrawEllipseFill(new Vector2i(deckRect.x + cornerSize, deckRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3)); RB.DrawEllipse(new Vector2i(deckRect.x + cornerSize, deckRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2)); RB.DrawEllipseFill(new Vector2i(deckRect.x + deckRect.width - cornerSize - 1, deckRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3)); RB.DrawEllipse(new Vector2i(deckRect.x + deckRect.width - cornerSize - 1, deckRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2)); RB.DrawEllipseFill(new Vector2i(deckRect.x + cornerSize, deckRect.y + deckRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3)); RB.DrawEllipse(new Vector2i(deckRect.x + cornerSize, deckRect.y + deckRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2)); RB.DrawEllipseFill(new Vector2i(deckRect.x + deckRect.width - cornerSize - 1, deckRect.y + deckRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3)); RB.DrawEllipse(new Vector2i(deckRect.x + deckRect.width - cornerSize - 1, deckRect.y + deckRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2)); RB.DrawRect(new Rect2i(deckRect.x + cornerSize, deckRect.y, deckRect.width - (cornerSize * 2), deckRect.height), DemoUtil.IndexToRGB(2)); RB.DrawRectFill(new Rect2i(deckRect.x + cornerSize, deckRect.y + 1, deckRect.width - (cornerSize * 2), deckRect.height - 2), DemoUtil.IndexToRGB(3)); RB.DrawRect(new Rect2i(deckRect.x, deckRect.y + cornerSize, cornerSize, deckRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(2)); RB.DrawRectFill(new Rect2i(deckRect.x + 1, deckRect.y + cornerSize, cornerSize - 1, deckRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(3)); RB.DrawRect(new Rect2i(deckRect.x + deckRect.width - cornerSize, deckRect.y + cornerSize, cornerSize, deckRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(2)); RB.DrawRectFill(new Rect2i(deckRect.x + deckRect.width - cornerSize - 1, deckRect.y + cornerSize, cornerSize, deckRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(3)); DrawSpinner(0, 0, spinnerSize); DrawSpinner(120, 0, spinnerSize); mMusicPlayButton.Render(); RB.CameraReset(); }