Jump to content

Some of my buttons are not showing up.


Haon1919
 Share

Recommended Posts

Hey guys! I am kinda new to PIXI so I apologize if there is a super obvious fix to this problem but I am having a super hard time getting display objects I called buttons to show up. Button 1 and the TilingSprite appear just fine but the rest of the buttons do not. I looked at the contents of app.stage in my console and it says the buttons are all in there. Thanks in advance for the help!

 

function playerSelect(){
    // var onClick = function(){  new characterSelect()};
    var stage = new PIXI.Container();
    stage.visible = true
    // var container = new PIXI.Container();
    var button1 = new Button("resources/button-small.png", 323, 162);

    var player1 = new Button("resources/player-select-buttons/1player-noselect.png", 293, 575);
    var player2 = new Button("resources/player-select-buttons/2player-noselect.png", 293, 575);
    var player3 = new Button("resources/player-select-buttons/3player-noselect.png", 293, 575);
    var player4 = new Button("resources/player-select-buttons/4player-noselect.png", 293, 575);
    //selected
    var player1Select = new Button("resources/player-select-buttons/1player-selected.png", 293, 575);
    var player2Select = new Button("resources/player-select-buttons/2player-selected.png", 293, 575);
    var player3Select = new Button("resources/player-select-buttons/3player-selected.png", 293, 575);
    var player4Select = new Button("resources/player-select-buttons/4player-selected.png", 293, 575);


    button1.position.x = 800;
    button1.position.y = 900;
    player1.position.x = 323;
    player1.position.y = 227;
    player2.position.x = 653;
    player2.position.y = 227;
    player3.position.x = 975;
    player3.position.y = 227;
    player4.position.x = 1300;
    player4.position.y = 227;

    player1Select.position.x = 323;
    player1Select.position.y = 227;
    player2Select.position.x = 653;
    player2Select.position.y = 227;
    player3Select.position.x = 975;
    player3Select.position.y = 227;
    player4Select.position.x = 1300;
    player4Select.position.y = 227;


    button1.on("mousedown", function(){
        stage.visible = false;
        new characterSelect()});
    player1.on("mousedown", function(){
        stage.addChild(player1Select)
        });
    player2.on("mousedown", function(){
        // stage.removeChildren();
        stage.addChild(player2Select)});
    player3.on("mousedown", function(){  app.stage.addChild(player3Select)});
    player4.on("mousedown", function(){  app.stage.addChild(player4Select)});
    player1Select.on("mousedown", function(){ console.log("hit")});


    app.stage = stage;

    var renderer = PIXI.autoDetectRenderer(
        1920,
        1080,
        {view:document.getElementById("game-canvas")}
    );
    //switch to png
    PIXI.loader
        .load(function(){
            var b = PIXI.Texture.fromImage("./resources/playerSelection-final.png");
            var tilingSprite = new PIXI.extras.TilingSprite(b, 1920, 1080);
            tilingSprite.alpha=0.5;
            stage.addChild(tilingSprite);
            stage.addChild(button1);
            stage.addChild(player2);
            stage.addChild(player1);
            stage.addChild(player3);
            stage.addChild(player4);
            renderer.render(stage);

        });




}
function Button(path, width, height) {
	var texture = PIXI.Texture.fromImage(path);
	PIXI.extras.TilingSprite.call(this, texture, width, height);

	this.tilePosition.x = 0;
	this.tilePosition.y = 0;
	this.interactive = true;
	this.buttonMode = true;

	this.viewportX = 0;
}

Button.prototype = Object.create(PIXI.extras.TilingSprite.prototype);



Button.prototype.setViewportX = function(newViewportX) {
	var distanceTravelled = newViewportX - this.viewportX;
	this.viewportX = newViewportX;
	this.tilePosition.x -= (distanceTravelled * button.DELTA_X);
};

 

Link to comment
Share on other sites

Yeah, loader will fix that. However, you didnt start the renderloop :) you need "render()" inside RAF. Its ok that buttons will be loaded after the fact. 

If you dont know what RAF is, I suggest you spend time on HTML5 canvas tutorials, and in pixi tutorial: https://github.com/kittykatattack/learningPixi

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...