• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sprite question

 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic