Get_transform不旋转图像

时间:2018-04-14 10:21:59

标签: python-3.x pyglet

我在pyglet中制作游戏已经有一段时间了,我遇到了一个我无法解决的错误。我试图使用image.get_transform(rotate = deg)旋转图像,但是得到错误

      function setup() {
      alphabet = "abcdefghijklmnopqrstuvwxyz";
      lives = 8;
      var words = ["ayeupmeducks", "pieceofcake", 
     "bullinachinashop", "hangfire","greeneyedmonster", 
     "hairraising","bringhomethebacon","adiamondintherough","onceinabluemoon",
     "afootinthedoor","bitethebullet"];

    messages = {
        win: 'Congratulations you have won the game of Hangman!',
        lose: 'You have been Hanged !!',
        guessed: ' already guessed, please try again...',
        validLetter: 'Please enter a letter from A-Z'
    };

      var getHint = document.getElementById("hint");
      var showClue = document.getElementById("clue");
      getHint.onclick = function() {
      hints = ["Stoke Greeting","Saying Something is Easy",
               "Very Clumsy","delaying something for a minute", 
               "When you are jealous of something",
              "Something is frightening", "Earn Money", 
              "Rough Exterior however has some potential", 
              "When something rarely happens", 
              "When you have succeeded/ getting yourself known by a company",
              "accepting something , when you do not want to"];

    var hintIndex = words
    showClue.innerHTML = "Clue: - " +  hints [idx];};

    gussedLetter = matchedLetter = '';
    numberofMatchedLetters = 0;
    var idx = Math.floor(Math.random() * words.length);
    var currentWord = words[idx];
    output = document.getElementById("output");
    message = document.getElementById("message");
    guessInput = document.getElementById("letter");
    message.innerHTML = 'You have ' + lives + ' lives remaining';
    output.innerHTML = '';
    document.getElementById("letter").value = '';

    guessButton = document.getElementById("guess");
    guessInput.style.display = 'inline';
    guessButton.style.display = 'inline';

    letters = document.getElementById("letters");
    letters.innerHTML = '<li class="current-word">Current word:</li>';
    var letter, i;
    for (i = 0; i < currentWord.length; i++) {
        letter = '<li class="letter letter' + currentWord.charAt(i).toUpperCase() + '">' + currentWord.charAt(i).toUpperCase() + '</li>';
        letters.insertAdjacentHTML('beforeend', letter);
    }
}

function gameOver(win) {
    if (win) {
        output.innerHTML = messages.win;
        output.classList.add('win');
    } else {
        output.innerHTML = messages.lose;
        output.classList.add('error');
    } 
    guessInput.style.display = guessButton.style.display = 'none';
    guessInput.value = '';
}

window.onload = setup();

document.getElementById("restart").onclick = setup;

guessInput.onclick = function () {
    this.value = '';
};
document.getElementById('hangman').onsubmit = function (e) {
    if (e.preventDefault) e.preventDefault();
    output.innerHTML = '';
    output.classList.remove('error', 'warning');
    guess = guessInput.value;

    if (guess) {
        if (alphabet.indexOf(guess) > -1) {
            if ((matchedLetter && matchedLetter.indexOf(guess) > -1) || (gussedLetter && gussedLetter.indexOf(guess) > -1)) {
                output.innerHTML = '"' + guess.toUpperCase() + '"' + messages.guessed;
                output.classList.add("warning");
            }
            else if (currentWord.indexOf(guess) > -1) {
                var lettersToShow;
                lettersToShow = document.querySelectorAll(".letter" + guess.toUpperCase());

                for (var i = 0; i < lettersToShow.length; i++) {
                     lettersToShow[i].classList.add("correct");
                }

                for (var j = 0; j < currentWord.length; j++) {
                    if (currentWord.charAt(j) === guess) {
                        numberofMatchedLetters += 1;
                    }
                }

                matchedLetter += guess;
                if (numberofMatchedLetters === currentWord.length) {
                    gameOver(true);
                }
            }
            else {
                gussedLetter += guess;
                lives--;
                message.innerHTML = 'You have ' + lives + ' lives remaining';
                if (lives === 0) gameOver();
            }
        }
        else {
            output.classList.add('error');
            output.innerHTML = messages.validLetter;
        }
    }
    else {
        output.classList.add('error');
        output.innerHTML = messages.validLetter;
    }
    return false;
};

我不知道如何解决这个问题,并且度数始终在-90到90之间,所以我不明白为什么这不起作用。代码中不起作用的部分是:

AssertionError: Only 90 degree rotations are supported.

getAngle函数是这样的:

deg=round(game.getAngle(x,y))
print(deg)
self.sprite=self.sprite.get_transform(rotate=deg)

任何帮助都会被认定

1 个答案:

答案 0 :(得分:0)

我不确定您使用的是哪个包,但另一种方法可能是使用来自scipy.image的旋转

查看文档here

代码基本上归结为使用:

from scipy import ndimage
rotated_image = scipy.ndimage.rotate(old_image, angle)