azurazen Posted February 15, 2018 Share Posted February 15, 2018 var roomHeight = 1600; var roomWidth = 2400; var game = new Phaser.Game(roomWidth, roomHeight, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.image('card','assets/demo_card.png'); game.load.image('cardBack','assets/demo_card_back.png'); } var bmd; function create() { selectedCard = false; cardHeight = 130; cardWidth = 80; cardSpc = 20; cursors = game.input.keyboard.createCursorKeys(); cardSprite = game.make.sprite(0, 0, 'card'); // World Setup game.world.setBounds(0, 0, 6000, 6000); game.camera.x = game.world.centerX - (roomWidth/2); game.camera.y = game.world.centerY - (roomHeight/2); game.stage.backgroundColor = 0x595959; game.physics.startSystem(Phaser.Physics.ARCADE); // Object creation cards = game.add.physicsGroup(); createDeck(game.world.centerX + cardSpc,game.world.centerY - cardHeight * 2, cardWidth, cardHeight); grave = createGraveyard(game.world.centerX - cardWidth * 2, game.world.centerY - cardHeight*2,cardWidth,cardHeight); // Rect Highlights, graphics setup (need to change name) graphics = game.add.graphics(100, 100); graphics.lineStyle(4, 0xFF0000, 1); graphics.drawRect(cardWidth/2-cardWidth, cardHeight/2-cardHeight, cardWidth, cardHeight); graphics.x-=1000; // BitmapData for drawing card selection to bmd = game.make.bitmapData(800,600); game.add.image(0,0,bmd); } function update() { if (cursors.up.isDown) { game.camera.y -= 10; } else if (cursors.down.isDown) { game.camera.y += 10; } if (cursors.left.isDown) { game.camera.x -= 10; } else if (cursors.right.isDown) { game.camera.x += 10; } game.physics.arcade.collide(grave, cards, discardCard, null, this); graphics.x = -500; graphics.y = -500; cards.forEach(function(item){ if(item.input.pointerOver()){ //graphics.drawRect(cardWidth/2+item.x, cardHeight/2+item.y, cardWidth, cardHeight); graphics.x = item.x; graphics.y = item.y; graphics.angle = item.angle; bmd.draw(item, game.world.centerX, game.world.centerY); } }); } Ive been messing with this for awhile and cannot figure out why it errors with an Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D', this occurs on the bmd.draw(item, game.world.centerX, game.world.centerY); line.. Any suggestions on where I messed up? Link to comment Share on other sites More sharing options...
Recommended Posts