question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting Started docs are outdated/broken

See original GitHub issue

I installed Excalibur v0.24.5 and started going through the getting started tutorial.

Issue # 1 (lastWorldPos does not exist)

In this code, evt.target.lastWorldPos does not exist in the current version:

// Add a mouse move listener
game.input.pointers.primary.on('move', function (evt) {
  paddle.pos.x = evt.target.lastWorldPos.x
})

I replaced it with paddle.pos.x = evt.pos.x and it seems to work.

Issue # 2 (confusing docs)

There are a few code blocks for the ball Actor. In the first code block it provides collision detection and custom drawing, then immediately after in the docs says how this code can be improved by using the already provided collision detection and custom drawing.

The collision detection and drawing code blocks aren’t needed since they are already provided. However, it might be helpful to break up that big code block for the ball Actor into smaller chunks, and move the comments out of the code and have it be documentation instead.

Issue # 3 (collision not working with provided code)

Just following the tutorial along as I go, this is the code I have so far. There is a paddle and a ball but the ball is not colliding with the paddle.

import * as ex from "excalibur";


const game = new ex.Engine({
    width: 800,
    height: 600
});

// Create an actor with x position of 150px,
// y position of 40px from the bottom of the screen,
// width of 200px, height and a height of 20px
const paddle = new ex.Actor({
    x: 150,
    y: game.drawHeight - 40,
    width: 200,
    height: 20
});

// Let's give it some color with one of the predefined
// color constants
paddle.color = ex.Color.Chartreuse;

// Make sure the paddle can partipate in collisions, by default excalibur actors do not collide
paddle.body.collider.type = ex.CollisionType.Fixed;

// `game.add` is the same as calling
// `game.currentScene.add`
game.add(paddle);

game.input.pointers.primary.on('move', function (evt) {
    paddle.pos.x = evt.pos.x;
})

// Create a ball
const ball = new ex.Actor(100, 300, 20, 20);

// Set the color
ball.color = ex.Color.Red;

// Set the velocity in pixels per second
ball.vel.setTo(100, 100);

// Set the collision Type to passive
// This means "tell me when I collide with an emitted event, but don't let excalibur do anything automatically"
ball.body.collider.type = ex.CollisionType.Passive;
// Other possible collision types:
// "ex.CollisionType.PreventCollision - this means do not participate in any collision notification at all"
// "ex.CollisionType.Active - this means participate and let excalibur resolve the positions/velocities of actors after collision"
// "ex.CollisionType.Fixed - this means participate, but this object is unmovable"

// Wire up to the postupdate event
ball.on("postupdate", () => {
    // If the ball collides with the left side
    // of the screen reverse the x velocity
    if (ball.pos.x < ball.width / 2) {
        ball.vel.x *= -1;
    }

    // If the ball collides with the right side
    // of the screen reverse the x velocity
    if (ball.pos.x + ball.width / 2 > game.drawWidth) {
        ball.vel.x *= -1;
    }

    // If the ball collides with the top
    // of the screen reverse the y velocity
    if (ball.pos.y < ball.height / 2) {
        ball.vel.y *= -1;
    }
});

// Draw is passed a rendering context and a delta in milliseconds since the last frame
ball.draw = (ctx, delta) => {
    // Optionally call original 'base' method
    // ex.Actor.prototype.draw.call(this, ctx, delta)

    // Custom draw code
    ctx.fillStyle = ball.color.toString();
    ctx.beginPath();
    ctx.arc(ball.pos.x, ball.pos.y, 10, 0, Math.PI * 2);
    ctx.closePath();
    ctx.fill();
};

// Add the ball to the current scene
game.add(ball);

ball.on('exitviewport', function () {
    alert('You lose!')
})

game.start();

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zskamljiccommented, Jun 22, 2021
  1. is still not fixed, I’ve tried using the suggested fix, but there’s an error at runtime: Uncaught TypeError: Cannot read property 'x' of undefined trying to log evt.target results in: image, implying that a wrong type is used in event.
0reactions
eonarheimcommented, Jun 26, 2021

@Kangaroux @gideongrinberg @zskamljic new getting started page is live, it’s now tied directly to the sample with snippet comments!

Let me know if you have additional feedback https://excaliburjs.com/docs/getting-started

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to troubleshoot damaged documents in Word - Office
Method 3: Create a link to the damaged document. Step 1: Create blank document. In Word, select the File Menu, and then select...
Read more >
Troubleshoot Google Docs, Sheets, Slides & Forms error ...
If you get an error message such as "Something went wrong. Reload" or "Unable to load file" preventing you from making edits on...
Read more >
Frequently Asked Questions - Read the Docs
Frequently Asked Questions¶. My project isn't building correctly¶. First, you should check out the Builds tab of your project. That records all of...
Read more >
Updating to New Releases - Create React App
We commit to keeping the breaking changes minimal so you can upgrade react-scripts painlessly.
Read more >
Troubleshoot damaged InDesign documents - Adobe Support
Identify and troubleshoot file issues · Run the disk repair utility tool for Windows or macOS. · Ensure that your system meets the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found