{"id":48217494,"url":"https://github.com/ractive/pxt-spritewrapper","last_synced_at":"2026-04-04T19:01:01.717Z","repository":{"id":140855497,"uuid":"262543685","full_name":"ractive/pxt-spritewrapper","owner":"ractive","description":"pxt-arcade extension to easily wrap a sprite in a class","archived":false,"fork":false,"pushed_at":"2020-05-10T11:36:12.000Z","size":825,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-12T00:21:38.486Z","etag":null,"topics":["makecode","makecode-arcade","makecode-arcade-extensions","makecode-extension"],"latest_commit_sha":null,"homepage":"https://ractive.github.io/pxt-spritewrapper/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ractive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-05-09T10:13:40.000Z","updated_at":"2022-10-28T14:14:26.000Z","dependencies_parsed_at":"2023-05-04T22:25:41.522Z","dependency_job_id":null,"html_url":"https://github.com/ractive/pxt-spritewrapper","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"purl":"pkg:github/ractive/pxt-spritewrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ractive%2Fpxt-spritewrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ractive%2Fpxt-spritewrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ractive%2Fpxt-spritewrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ractive%2Fpxt-spritewrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ractive","download_url":"https://codeload.github.com/ractive/pxt-spritewrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ractive%2Fpxt-spritewrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31409471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["makecode","makecode-arcade","makecode-arcade-extensions","makecode-extension"],"created_at":"2026-04-04T19:00:45.389Z","updated_at":"2026-04-04T19:01:01.697Z","avatar_url":"https://github.com/ractive.png","language":"TypeScript","readme":"\n# pxt-spritewrapper ![Build Status Abzeichen](https://github.com/ractive/pxt-spritewrapper/workflows/MakeCode/badge.svg)\n\nThis extension allows you to easily wrap a sprite in a class and get the corresponding class instance\nwhen given a given sprite. Your class needs to extend the `SpriteWrapper.Support` base class.\nYour object's `onDestroyed` method is set as a callback to the sprite's `onDestroyed` method.\nWhenever the sprite gets destroyed, the `onDestroyed` method of your object is called, so that you can\ndo some clanup. To destroy an object yourself, call the `destroy` method of its \nsprite or call the `destroy` method directly on the object.\n\nHere's a very simple space shooter game that demonstrates how to use it:\n```\nclass EnemySpaceShip extends SpriteWrapper.Support {\n    private static readonly image: Image = img`\n        5 5 5 5 5 5 d\n        . 5 5 5 5 d .\n        . . 5 5 d . .\n        . . . 5 . . .\n    `;\n\n    constructor(xPos: number) {\n        super(sprites.create(EnemySpaceShip.image, SpriteKind.Enemy));\n        this.sprite.setFlag(SpriteFlag.AutoDestroy, true);\n        this.sprite.y = 0;\n        this.sprite.x = xPos;\n        this.sprite.vy = 50;\n    }\n\n    public gotHit() {\n        info.changeScoreBy(10);\n        this.destroy();\n    }\n}\n\nclass SpaceShip extends SpriteWrapper.Support {\n    private static readonly image: Image = img`\n        . . . d . . .\n        . . 1 1 d . .\n        . 1 1 1 1 d .\n        1 1 1 1 1 1 d\n    `;\n\n    constructor() {\n        super(sprites.create(SpaceShip.image, SpriteKind.Player));\n        this.sprite.setFlag(SpriteFlag.AutoDestroy, true);\n        this.sprite.y = scene.screenHeight() - 10;\n        this.sprite.setFlag(SpriteFlag.StayInScreen, true);\n\n        controller.left.onEvent(ControllerButtonEvent.Pressed, function () {\n            this.flyLeft();\n        });\n        controller.right.onEvent(ControllerButtonEvent.Pressed, function () {\n            this.flyRight();\n        });\n        controller.A.onEvent(ControllerButtonEvent.Pressed, function () {\n            this.shoot();\n        });\n    }\n\n    public onDestroyed() {\n        music.powerDown.play();\n        game.over(false);\n    }\n\n    public flyLeft() {\n        this.sprite.vy = 0;\n        this.sprite.vx = -50;\n    }\n\n    public flyRight() {\n        this.sprite.vy = 0;\n        this.sprite.vx = 50;\n    }\n\n    public shoot() {\n        sprites.createProjectileFromSprite(img`\n            1\n        `, this.sprite, 0, -70);\n    }\n}\n\nconst player: SpaceShip = new SpaceShip();\n\ngame.onUpdateInterval(1000, () =\u003e {\n   new EnemySpaceShip(randint(0, scene.screenWidth()));\n});\n\nsprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, (playerSprite: Sprite, enemySprite: Sprite) =\u003e {\n    SpriteWrapper.fromSprite(playerSprite).destroy();\n    SpriteWrapper.fromSprite(enemySprite).destroy();\n});\n\nsprites.onOverlap(SpriteKind.Projectile, SpriteKind.Enemy, (projectileSprite: Sprite, enemySprite: Sprite) =\u003e {\n    (SpriteWrapper.fromSprite(enemySprite) as EnemySpaceShip).gotHit();\n    projectileSprite.destroy();\n});\n```\n\n\n## Using it in your project\n\nTo use this extension in your project, choose \"Advanced \u003e Extensions...\" and enter `https://github.com/ractive/pxt-spritewrapper` in the search box.\n\n#### Metadata (used for search, rendering)\n\n* for PXT/arcade\n\u003cscript src=\"https://makecode.com/gh-pages-embed.js\"\u003e\u003c/script\u003e\u003cscript\u003emakeCodeRender(\"{{ site.makecode.home_url }}\", \"{{ site.github.owner_name }}/{{ site.github.repository_name }}\");\u003c/script\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fractive%2Fpxt-spritewrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fractive%2Fpxt-spritewrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fractive%2Fpxt-spritewrapper/lists"}