% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={python/pysfml-animatedsprite-class-supplies-next-method-to-adjus},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{python/pysfml-animatedsprite-class-supplies-next-method-to-adjus}
\author{}
\date{}

\begin{document}
\maketitle

\hypertarget{pythonpysfml-animatedsprite-class-supplies-next-method-to-adjus}{%
\section{python/pysfml-animatedsprite-class-supplies-next-method-to-adjus}\label{pythonpysfml-animatedsprite-class-supplies-next-method-to-adjus}}

\hypertarget{pysfml-animatedsprite-class-supplies-next-method-to-adjust-frames}{%
\section{PySFML AnimatedSprite class supplies Next method to adjust
frames}\label{pysfml-animatedsprite-class-supplies-next-method-to-adjust-frames}}

.. code-block:: python

from PySFML import sf

class AnimatedSprite( sf.Sprite ): def \textbf{init}( self, image,
columns=1, rows=1, sequence=None, columnwidth=None, rowheight=None ):
super( AnimatedSprite, self ).\_\_init\_\_( image )

\begin{verbatim}
     totalwidth, totalheight = self.GetSize() 

     if columnwidth: self.columnwidth = columnwidth 
     else: self.columnwidth = int( totalwidth / columns )

     if rowheight: self.rowheight = rowheight
     else: self.rowheight = int( totalheight / rows )

     if sequence:
         self.sequence = sequence
     else:
         self.sequence = [ number for number in range( 1, ( columns * rows ) + 1 ) ]

     # create a frames list of column and row tuples
     self.frames = [ (x,y) for y in range( 1, rows + 1 ) for x in range( 1, columns + 1 ) ]

     self.current = self.tick = self.complete = 0

     # set the first frame 
     self.Next( self.tick )

 def Next( self, tickrate = 12 ):
     """
     Pass an optional tickrate.
     If tick is greater or equal to tickrate:
     Move the Sub Rectangle or view to the Next position.
     Set complete to True when sequence finishes.
     """
     self.tick += 1

     if self.tick >= tickrate:

         self.tick = 0
         column, row = self.frames[ self.sequence[ self.current ] - 1  ]

         subrect = sf.IntRect( 
             self.columnwidth * ( column - 1 ), 
             self.rowheight * ( row - 1 ), 
             self.columnwidth * column,
             self.rowheight * row
         ) 

         self.SetSubRect( subrect ) 

         self.current += 1
         if self.current >= len( self.sequence ):
             self.complete = True
             self.current = 0
\end{verbatim}

\hypertarget{some-example-sprite-timeline-images}{%
\section{Some example sprite timeline
images}\label{some-example-sprite-timeline-images}}

.. image:: /attachment/numbers.png :alt:

\end{document}
