Skip to content

Instantly share code, notes, and snippets.

View AchrafKassioui's full-sized avatar

Achraf Kassioui AchrafKassioui

View GitHub Profile
@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.
@AchrafKassioui
AchrafKassioui / module-boilerplate-1.js
Last active February 22, 2019 11:57
Boilerplate for JavaScript plugin with export
// Based on https://github.com/highlightjs/highlight.js/blob/master/src/highlight.js
(function(factory) {
// Find the global object for export to both the browser and web workers.
var globalObject = typeof window === 'object' && window || typeof self === 'object' && self;
// Setup MyPlugin.js for different environments. First is Node.js or CommonJS.
if(typeof exports !== 'undefined') {
factory(exports);
} else if(globalObject) {
// Export MyPlugin globally even when using AMD for cases when this script
@AchrafKassioui
AchrafKassioui / constructor-boilerplate-1
Last active February 22, 2019 11:55
Boilerplate for JavaScript plugin with constructor
// Based on https://raw.githubusercontent.com/mozilla/readability/master/Readability.js
function Constructor(options) {
}
Constructor.prototype = {
};