Sprite.forever?

Open
#757 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
game-dev

Research direction

Start by reviewing the Sprite instance API and game.onUpdateInterval usage shown in the issue. Clarify how a per-sprite forever callback should behave for newly created baddies, including its interval and callback context. Done means the proposed Sprite.forever behavior is specified and implemented with coverage for the relevant lifecycle cases.

Written by the indexing model from the issue text.

Description

api enhancement help wanted

I'm always frustrated when I have to write a game loop, it seems very 1980s. Given the asynchronicity of the language I think it would be much cooler to have a forever loop for each instance of a sprite.

For instance, here's a little excerpt from a game I was playing with:

// baddie movement
game.onUpdateInterval(30, function () {
    ticks += 1
    console.log("T")
    if (baddie.x < queen.x) {
        baddie.vx = 20
        if (ticks > 4) {
            baddie.setImage(baddieRight)
        }
    } else {
        baddie.vx = -20
        if (ticks > 4) {
            baddie.setImage(baddieLeft)
        }
    }
    if (baddie.y < queen.y) {
        baddie.y++;
    } else if (baddie.y > queen.y) {
        baddie.y--;
    }
    if (ticks == 60) {
        ticks = 0
        sprites.createProjectileFromSprite(baddieProjectile, baddie, 4 * baddie.vx, 0)
        baddie.setImage((baddie.vx) ? baddieRightThrow : baddieLeftThrow)
    }
})

Note the comment above: this code is specific to the baddie sprite. Ideally I want this code to run every time there's a baddie created.

When really the code above should "belong" to a sprite and look a little something like this:

// baddie movement
baddie.forever(30, function () {
    ticks += 1
    .....
    this.x++;
    .....
})
Dominant language
TypeScript
Stars
546
Forks
263
Avg merge
7h 35m
Merged PRs (30d)
46

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/pxt-arcade

All issues in microsoft/pxt-arcade

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.