• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sprite question

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm new to sprite and have been experiencing game development using game canvas. However, i've a basic question about sprite, do i need to provide 3 images in res directory suppose i want to display the image's sprite in 3 frames? because i've tried to use sprite displaying 3 frames using only one image and it throws an exceptions
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taken from Jonathan Knudsen's book from Apress publishing.

"Interestingly, a Sprite cannot be created from seperate frame images; the frames must be packed into a single source image.



So the sprite must be in one file.

The total number of frames contained in the Sprite is returned from getRawFrameCount()



Looking further in the book he has a Sprite that has 4 frames, each frame is 48x48, so the single file itself is 192x48 pixels.

He has an int array to define the frame sequence for this guy running. He then creates an Image object from the .png file using Image.createImage() passing the filename. Then he creates a Sprite object passing in the Image and then the size of a frame, so new Sprite(image, 48, 48);
then he takes the Sprite object and calls setFrameSequence() passing in the int array.

Does that help. Also can you post the Exception and stack trace?

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic