Find a spritesheet that contains images about character moving in four different
ID: 3919458 • Letter: F
Question
Find a spritesheet that contains images about character moving in four different directions. For example, it can look similar to the following (of course, you can also use the below example spritesheet if you like) Based on movingDog.zip and spriteSheetAnimation pde write a Processing program to create an animation that can move the animated character with key pressings in the game window. The character images are those read from the spritesheet. Different directions should have different animations. For example, if we use the above shown spritesheet, when you press the left key, you will only see the animation created from the four images in the second row. Similarly, pressing the up key will show a character moving up. Note when you release the key, the animation should stop Hint: in spriteSheetAnimation.pde, we get sprite images using "PImage sprite spritesheet.get(x, y, W, H):", where x is a horizontal stride of the character's width, and y is a vertical stride of the character's height. So, when draw0 is iterated, we can pick up every small character image from the whole spritesheet with a horizontal stride andor a vertical stride (vertical stride only takes place when we finish one row of character images and switch to the next row). In this assignment, if you press an arrow key, say, LEFT, you only pick up every small chacter age from the 2nd row with horizontal strides, i.e. you can use the following iftkeyCodeLEFT && keyPressed true&sprite; spritesheet.get(x, H, W, H). ··· ? You can write similar statements for moving in the other three directions. Carefully design the screen layout and add text to your game window. When the character reaches the boundary of the game world, i.e. one of the four walls, he will stop and your game will display the text such as "Slop!". When he leaves the boundary, the text will change to something clse such as "This is the game world When the character reaches the boundary, he will shrink half in both x and y directions (i.e. become 1/4 of its original size). Due to scaling, you may notice that he also changes his position. Try to make the character stay at the same position before and after scaling. It's ok if there may still have a small horizontal difference, because the character images are not tightly packed in the spritesheet (for example, in the above spritesheet, a character sprite keeps a distance to his left and right neighbors). We don't want the character's position to have big difference in vertical before and after scalingExplanation / Answer
Sprite Retrieval Class :
Animation Class :
The animation class has start, stop, restart and reset to control the animation. You could easily add a boolean to test whether it should loop or not.
Frame Class :
The Frame class holds an image and a duration associated with that image.
The way I implement the animation is as follows:
Player.java
In your update or tick method you will have:
Draw method you will have:
Lets say you have implemented MouseListener
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.