Jump to content

Wrong sprite.y displaying


Timofii
 Share

Recommended Posts

Hi! When i increment sprite.y coordinate inside the game loop, the sprite moves to bottom, like y increment is below zero. Console values of increment and sprite.y is above zero.

Attaching my code:

let renderer, stage, character, sprite;
const alpha = 45, tanAlpha = Math.tan(alpha / 180*Math.PI);

function setup () {
    renderer = PIXI.autoDetectRenderer(
        {backgroundAlpha: 0});

    character = PIXI.Texture.from('Content\\images\\slogosb.png');

    stage = new PIXI.Container();

    sprite = new PIXI.Sprite(character);

    stage.addChild(sprite);

    document.getElementById('view').appendChild(renderer.view);

    animate();
}


function animate () {
//Loop this function 60 times per second
    requestAnimationFrame(animate);
    //Move the sprite 1 pixel per frame
    sprite.x += 0.5;
    sprite.y = sprite.x * tanAlpha;
    //Render the stage
    renderer.render(stage);
}

setup();
Link to comment
Share on other sites

Yep ... think of it as "reading a page" rather than "flying a plane" then it'll make a bit more sense until it becomes automatic.

Why is Y down?  iirc it's to do with gravity, and how on early raster displays there are no lines, just a gradual droop of the ray with a period return of the X, and a period return of the Y as a multiple of the X period.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...