"spritesheets in pyqt" Code Answer's

You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "spritesheets in pyqt" answered properly. Developers are finding an appropriate answer about spritesheets in pyqt related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like spritesheets in pyqt. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on spritesheets in pyqt. 

spritesheets in pyqt

By Clean ChinchillaClean Chinchilla on Jul 10, 2020
# -*- coding: utf-8 -*-
import sys
import time

from PyQt4 import QtGui, QtCore


class SpriteAnimation(object):
    def __init__(self, image_path, sprite_width, sprite_height, label):
        pixmap = QtGui.QPixmap(image_path)

        width, height = pixmap.width(), pixmap.height()
        self.pixmaps = []
        for x in range(0, width, sprite_width):
            for y in range(0, height, sprite_height):
                self.pixmaps.append(pixmap.copy(x, y, 
                                                sprite_width, sprite_height))
        self._current_frame = 0
        self.label = label

    def play(self, interval=100):
        self._timer = QtCore.QTimer(interval=interval,
                                    timeout=self._animation_step)
        self._timer.start()
    def _animation_step(self):
        self.label.setPixmap(self.pixmaps[self._current_frame])
        self.label.update()
        self._current_frame += 1
        if self._current_frame >= len(self.pixmaps):
            self._current_frame = 0


class Window(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.resize(100, 100)
        layout = QtGui.QVBoxLayout(self)
        label = QtGui.QLabel()
        layout.addWidget(label)
        # http://content.makeyourflashgame.com/pbe/tutorials/star-green.png
        self.animation = SpriteAnimation('star-green.png', 80, 80, label)
        self.animation.play()


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

Source: stackoverflow.com

Add Comment

0

spritesheets in pyqt

By Clean ChinchillaClean Chinchilla on Jul 10, 2020
class PowerUp(QtGui.QGraphicsRectItem):
    def __init__(self):
        QtGui.QGraphicsRectItem.__init__(self)
        self.images = ['data/images/objects/bonus_block/full-0.png',
                       'data/images/objects/bonus_block/full-1.png',
                       'data/images/objects/bonus_block/full-2.png',
                       'data/images/objects/bonus_block/full-3.png',
                       'data/images/objects/bonus_block/full-4.png']
        self.image = self.images[0]
        self.current = 0
        self.position()
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.animation_step)
        self.timer.start(175)
        #random.choice([slide(), ghost()])

    def position(self):
        self.pos_x = random.randint(-300, 300)
        self.pos_y = random.randint(-200, 200)

    def boundingRect(self):
        return QtCore.QRectF(0, 0, 32, 32)

    def paint(self, painter, option, widget):
        painter.setBrush(QtGui.QBrush(self.image))
        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        painter.drawRect(0, 0, 32, 32)
        self.setPos(self.pos_x, self.pos_y)

    def animation_step(self):
        self.image = QtGui.QPixmap(self.images[self.current])
        self.current += 1
        if self.current == len(self.images):
            self.current = 0

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the TypeScript based application and are stuck on spritesheets in pyqt can get a collection of related answers to their query. Programmers need to enter their query on spritesheets in pyqt related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about spritesheets in pyqt for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of spritesheets in pyqt while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "spritesheets in pyqt". Visit this developer's friendly online web community, CodeProZone, and get your queries like spritesheets in pyqt resolved professionally and stay updated to the latest TypeScript updates. 

TypeScript answers related to "spritesheets in pyqt"

View All TypeScript queries

TypeScript queries related to "spritesheets in pyqt"

Browse Other Code Languages

CodeProZone