Skip to content

Instantly share code, notes, and snippets.

View AchrafKassioui's full-sized avatar

Achraf Kassioui AchrafKassioui

View GitHub Profile
@AchrafKassioui
AchrafKassioui / SpriteMotionBlur.swift
Last active June 21, 2026 00:46
SpriteKit motion blur shader experiment. This is the SpriteKit version of https://github.com/alexwidua/zoom-motion-blur
/**
# Sprite Motion Blur
This scene implements per-sprite motion blur with a fragment shader.
The sprite is larger than the visible shape, so the shader has transparent drawing room around the circle.
Each fragment samples the sprite texture several times along the current movement direction, then averages those samples into one final color.
The scene updates the blur direction and length from the sprite physics velocity.
@AchrafKassioui
AchrafKassioui / SpriteKitLineShader.swift
Last active June 18, 2026 02:27
A minimal setup to start with SpriteKit shaders. This shader draws a line from point A to point B.
/**
# Line Shader
A minimal setup to start with SpriteKit shaders.
This setup uses a sprite as a drawing canvas.
A shader draws a line from point A to point B.
Touching the scene anywhere updates the point B location and the shader's drawing.
@AchrafKassioui
AchrafKassioui / SKDeterminism.swift
Last active June 18, 2026 02:28
SpriteKit Physics Determinism
/**
# SpriteKit Physics Determinism
Is SpriteKit's physics engine deterministic?
In some cases, the physics-based behavior is quite repeatable.
In other cases, the simulation yields a different outcome every run.
This is a setup to explore such behaviors.
Press one of the buttons to play a sequence.
@AchrafKassioui
AchrafKassioui / ManualCamera.swift
Last active June 18, 2026 02:28
Code sample for manual camera setup in SpriteKit.
/**
Code sample for manual camera setup in SpriteKit.
Achraf Kassioui
Created 27 August 2025
Updated 28 August 2025
*/
import SpriteKit
@AchrafKassioui
AchrafKassioui / MemoryBuildUp.swift
Created November 23, 2024 05:01
Testing memory build up of a SpriteKit scene when it is presented again and again.
/**
# SpriteKit Memory Buildup
Testing memory build up of a SpriteKit scene when it is presented again and again.
Achraf Kassioui
Created 23 November 2024
Updated 23 November 2024
@AchrafKassioui
AchrafKassioui / LeakInvestigation.swift
Last active November 22, 2024 21:49
Investigating a possible memory leak in SpriteKit SKTileMapNode. See this GitHub project: https://github.com/sanderfrenken/sktilemap-rect-in
/**
# Investigating SKTileMapNode Memory Leak
Achraf Kassioui
Created 22 November 2024
Updated 22 November 2024
*/
@AchrafKassioui
AchrafKassioui / GKSK.swift
Last active October 29, 2024 19:56
Testing GameplayKit's GKSKNodeComponent with SpriteKit.
/**
# Testing GKSKNodeComponent
Apple documentation: https://developer.apple.com/documentation/gameplaykit/gksknodecomponent
A GKSKNodeComponent is a special class of component that contains a node by default.
When a GKSKNodeComponent is added to an entity, the `node.entity` property of the node is automatically assigned.
Whereas if we use a regular GKComponent with a node inside it, we must assign that property manually inside `didAddToEntity` and `willRemoveFromEntity`.
Note that in both cases, the SpriteKit scene must hold a strong reference to the entity in order to retrieve it.
@AchrafKassioui
AchrafKassioui / JointsWithCamera.swift
Last active May 29, 2024 02:03
A SpriteKit scene to investigate how physics joints work across various camera scales.
/**
# Physics Joints and Camera
A scene to investigate how physics joints work across various camera scales.
Achraf Kassioui
Created: 28 May 2024
Updated: 29 May 2024
@AchrafKassioui
AchrafKassioui / Pan and Rotate in SpriteKit.md
Last active April 15, 2024 23:26
A setup to control SpriteKit camera with gestures

Intuitive camera control in SpriteKit

I'm implementing multi-touch camera control in SpriteKit using UIKit gesture recognizers, and I have troubles making pan and rotate work intuitively together.

From a user interface perspective, the goal is:

  • A pan gesture moves the scene as you'd expect, adjusting for camera rotation.
  • A pinch gesture scales the scene as you'd expect, with the camera zooming in and out from the midpoint of the gesture, not the view center.
  • A rotation gesture should rotate the scene as if it were a piece of paper that you manipulate with two fingers. The gesture midpoint at the start of the rotation defines the rotation pivot.
@AchrafKassioui
AchrafKassioui / ChainCIFilter.swift
Last active May 20, 2024 23:30
Run multiple Core Image filters on the same node in SpriteKit and prevent Metal crashes
/**
# ChainCIFilter.swift
In Apple SpriteKit, you can use Core Image filters to add effects to nodes of type `SKEffectNode`, including the scene itself.
However, the built-in SpriteKit API only takes one filter at a time, and the output can crash SpriteKit's renderer if the result exceeds Metal texture size limit.
This custom `CIFilter` sub-class provides a solution for both issues:
- You can run multiple filters on the same effect node.
- The size of the generated output is checked against a size limit, and is sent to SpriteKit only if the limit is not exceeded.