Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:17:43+00:00 2026-06-17T04:17:43+00:00

I have files (*.png) with animation. Each file – frame. So 10 files –

  • 0

I have files (*.png) with animation. Each file – frame. So 10 files – 10 frames. Full animation repeat 4 times. So I need render images 20 times.

DiceAnim1=pygame.image.load('Gfx/Dices/dice0042.png').convert_alpha()
DiceAnim2=pygame.image.load('Gfx/Dices/dice0043.png').convert_alpha()
DiceAnim3=pygame.image.load('Gfx/Dices/dice0044.png').convert_alpha()
DiceAnim4=pygame.image.load('Gfx/Dices/dice0045.png').convert_alpha()
DiceAnim5=pygame.image.load('Gfx/Dices/dice0046.png').convert_alpha()
DiceAnim6=pygame.image.load('Gfx/Dices/dice0047.png').convert_alpha()
DiceAnim7=pygame.image.load('Gfx/Dices/dice0048.png').convert_alpha()
DiceAnim8=pygame.image.load('Gfx/Dices/dice0049.png').convert_alpha()
DiceAnim9=pygame.image.load('Gfx/Dices/dice0050.png').convert_alpha()
DiceAnim10=pygame.image.load('Gfx/Dices/dice0051.png').convert_alpha()

Can anyone suggest function with minimal code length.
Initiation in main programm loop:

if event.type == pygame.MOUSEBUTTONDOWN:
    if gameState==7:
        if 165<pointer_coord[0]<424 and 249<pointer_coord[1]<607 : 
            gameState=9
            rolling=1

This is mean is user click in area (x=165, y=249, length=424-165, height=607-249), then game enter to state 9. State 9 – was created for playing animation.

if gameState==9:
        RollingAnimation(166,253)
        RollingAnimation(210,278)
        RollingAnimation(166,303)
        RollingAnimationControl()

This function RollingAnimation is:

def RollingAnimation(tx,ty):
    global diceTikTac
    screen.blit(DiceAnimShadow,[tx,ty])
    if diceTikTac==1: screen.blit(DiceAnim1,[tx,ty])
    if diceTikTac==2: screen.blit(DiceAnim2,[tx,ty])
    if diceTikTac==3: screen.blit(DiceAnim3,[tx,ty])
    if diceTikTac==4: screen.blit(DiceAnim4,[tx,ty])
    if diceTikTac==5: screen.blit(DiceAnim5,[tx,ty])
    if diceTikTac==6: screen.blit(DiceAnim6,[tx,ty])
    if diceTikTac==7: screen.blit(DiceAnim7,[tx,ty])
    if diceTikTac==8: screen.blit(DiceAnim8,[tx,ty])
    if diceTikTac==9: screen.blit(DiceAnim9,[tx,ty])
    if diceTikTac==10: screen.blit(DiceAnim10,[tx,ty])

To control animation I use a control function RollingAnimationControl:

def RollingAnimationControl():
    global radiobuttonPos,diceTikTac,round1,gameState
    diceTikTac=diceTikTac+1
    if diceTikTac==11: 
        round1=round1+1
        diceTikTac=1
    if round1>4: # how much need loops animation.
        gameState=11
        diceTikTac=1            
        rolling=0
        round1=0

Question is: How I can minimized this function. Can you imagine how would looks this function if animtion was use 100 files with frames.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:17:44+00:00Added an answer on June 17, 2026 at 4:17 am

    For loading the animations, you can use a for loop to go through the things you need to load, because of their convinient naming (good job on that):

    frames=[]
    for i in range(42, 52):
        frames.append(pygame.image.load('Gfx/Dices/dice00'+str(i)+'.png').convert_alpha())
    

    Now that the frames are all in a list, it makes it much easier to blit them.

    for frame in frame:
        screen.blit(frame, ???)
    

    In this way, you can blit and load your animation without any long or repetative

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder in my WPF app Images that has several .png files
I have like 45 PNG files that I want to use in a animation
I have small animation using javascript and css. I made one sprite png file,
I have generated a bunch of png files to use as markers on my
I have two files and the content is as follows: alt text http://img144.imageshack.us/img144/4423/screencapture2b.png alt
I have a Flash web app which displays user submitted PNG files. Files are
I have a folder on my remote server that has a few .png files
I have a curious problem with IE, IIS 6.0 dynamic PNG files and I
Help needed! I have 10 different .png files and i want to display them
I have several png image files with names like this - house_number_5.png house_number_512.png house_number_52352.png

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.