Tutorial on using Java Sprite Animation

Slides:



Advertisements
Similar presentations
GAME:IT Junior Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a.
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.
Getting to know Greenfoot
A tour around Java General introduction to aspects of the language (these will be covered in more detail later) After this tour you should have a general.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0 Key Abstractions in Game Maker Foundations of Interactive Game Design Prof. Jim Whitehead.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Game Maker Day 2 Making a Maze Game.
Summer Computing Workshop. Session 2 Input in Scratch  Multi-Character input - This is used when the user is prompted to enter a number or word.  Problems.
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
Game Maker Terminology
Game Maker – Getting Started What is Game Maker?.
Shooters in GameMaker J Parker.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
GAME:IT Junior Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a.
GAME:IT Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a simple.
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
School of Computer Science Space School 2015 Programming a Lunar Lander Game.
MOM! Phineas and Ferb are … Aims:
Animation Through The Ages
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Working with Tabs and Tables
Animated picture effects for PowerPoint slides
An Introduction to Spritesheet Animation
A Tutorial on How to Turn PowerPoint Presentations into Slideshows
Chap 7. Building Java Graphical User Interfaces
Chapter 5 Working with Images
Graphical User Interfaces -- Introduction
Introduction to Object-Oriented Programming
Introduction to.
BYOB – Costumes.
Learn… Create… Program
Multimedia Authoring Tools
Chapter III Animations, Transitions, Spell Check, Outline Tab, Slides Tab, Sorter View, and Printing Saturday, November 24, 2018Saturday, November 24,
Lesson 1 Introduction to Scratch Basic blocks
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Learn… Create… Program
Tank Game Part 6 of 6.
Otasuke GP-EX! Chapter 1 Menu Screen.
Tank Game Part 2 of 6.
Game Loop Update & Draw.
Introduction to scratch animation
Multithreaded Programming
ICT Spreadsheets Lesson 1: Introduction to Spreadsheets
ICT Gaming Lesson 3.
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Tank Game Int 10 Unit 3 – Game Maker.
2.02D Computer Animation Software and Design Guidelines
The coordinate system Susan Ibach | Technical Evangelist
Using Animation and Multimedia
Learn… Create… Program
Learn… Create… Program
CS297 Graphics with Java and OpenGL
Game Programming Algorithms and Techniques
CSC 221: Introduction to Programming Fall 2018
TC 310 The Computer in Technical Communication
Chapter 7 The Game Loop and Animation
Animation Translation.
Presentation transcript:

Tutorial on using Java Sprite Animation Sagar Patel

Agenda Introduction Basic Sprite Animation Sprite Structure Object Structure Defining Action Functions Programming Difficulties Examples and ScreenShots 12/4/2018

Introduction The idea of sprite animation is simple. Draw the object in a position. Wait a while. Draw the object in a new position. Go back to second step. 12/4/2018

Introduction (cont’d) A sprite animation differs from traditional video animation. Using the metaphor of a sprite animation as a theatrical play, sprite tracks are the boundaries of the stage, a sprite world is the stage itself, and sprites are actors performing on that stage. Each sprite has properties that describe its location and appearance at a given time. 12/4/2018

Introduction (cont’d) During the course of an animation, you modify a sprite’s properties to cause it to change its appearance and move around the set or stage. Each sprite has a corresponding image and during the animation, you can change a sprite’s image. For example, you can assign a series of images to a sprite in succession to perform cell-based animation. Sprites can also be mixed with still-image graphics to produce a wide variety of effects while using relatively little memory. 12/4/2018

Basic Sprite Animation A simplistic sprite would not be very interesting in a modern computer game. In modern games, we want to look at sprites that have a wider range of motion: a hero sprite, for example, who runs, jumps, kicks, and shoots; or an enemy robot sprite that rolls, bumps into walls, and emits electrical charges. In order for a game to be competitive in the current market, the sprite animation needs to be creative and sophisticated. Maintaining control of such sophisticated sprite action can be a challenge. 12/4/2018

Sprite Structure The basic building block of the sprite is the sprite structure, which is defined like this in the C language: /* sprite structure */ typedef struct _sprite {   char *bitmap;   int width;   int height; int xoffset;   int yoffset; } SPRITE; 12/4/2018

Sprite Structure (cont’d) This structure holds the information necessary to display the sprite, including its width and height, the bitmap that defines the image, and the offset values. The offsets are used to adjust the position of the sprite, and are useful with things like explosions, which must be centered around a midpoint, rather than displayed from a corner. 12/4/2018

Object Structure The sprite structure is a member of the object structure, which is defined like this: /* forward declarations */ struct OBJstruct; typedef struct OBJstruct OBJ, near *OBJp; /* pointer to object action function */ typedef void near ACTION (OBJp objp); typedef ACTION *ACTIONp; 12/4/2018

Object Structure (cont’d) /* data structure for objects */ typedef struct OBJstruct {   OBJp next; OBJp prev;   int x,y;   int xspeed,yspeed;   int max_xspeed;   int direction;   int frame;   int tile_xmin,tile_xmax;   int tile_ymin,tile_ymax; SPRITE *image;   ACTIONp action; }; 12/4/2018

Object Structure (cont’d) This data structure contains all the information about a particular object in the game, including its position (x and y coordinates), its vertical and horizontal speed, the direction it is facing, the frame of animation (for example, which stage of a six-stage walk), 12/4/2018

Object Structure (cont’d) the tile extents (how close the sprite may approach the edge of the screen), and a pointer to the sprite image, which was defined earlier. The sprite image changes as the sprite moves, and may represent a sprite as walking, running, or shooting, for example. 12/4/2018

Defining Action Functions The last member of the object structure is the pointer to the action function, which is where all the interesting work takes place. The action function is a function which is executed once each frame for each sprite. It performs several tasks. It causes the sprite to move (by changing the object's x and y coordinates), it checks for collisions, it may spawn new objects or kill off old ones, but most importantly, the action function determines what the object will do in the next frame. It does this by specifying the next action function. 12/4/2018

Defining Action Functions (cont’d) Here is an example of an action function in its simplest form: void near sprite_stand(OBJp objp) {   if (fg_kbtest(LEFT_ARROW))     objp->action = sprite_walk; } This is the action function for a sprite standing still. As you can see, the sprite does nothing. Its x and y coordinates do not change, and its sprite image does not change. 12/4/2018

Defining Action Functions (cont’d) Also, as long as no key is pressed, the sprite's action function does not change. As long as the sprite continues to stand still, this action function will continue to be called once each frame. The state of the sprite changes from standing to walking when the left arrow key is pressed. When this happens, the sprite_stand() function is abandoned, and the sprite_walk() function takes over. This transition happens very simply: a pointer in the object structure is reassigned to point to a new action function. 12/4/2018

Programming Difficulties The difficult part in programming sprite animation is deciding what should go in the action functions. Since a sprite can do more than one thing at a time (shooting while jumping, for example), the programmer must make decisions about which action function should be called. The choice would be calling the sprite_shoot() function, with the jumping action being an incidental action happening within the shooting function, or calling the sprite_jump() function, with the shooting action incidentally happening within the jumping function. 12/4/2018

Examples and Screen Shots In this section we are going to see two examples of Sprite Animation. You can also see the examples and run the applet on the following website: http://web.njit.edu/~gblank/CIS602/sprite/SpriteAnimation.html 12/4/2018

Examples and ScreenShots (cont’d) Example 1: A sprite animation which moves a rectangle along a diagonal line with a scrollbar for determining the delay between frames. The default delay is set to 100. See the screen shots of this example in the next slide. 12/4/2018

Examples and ScreenShots (cont’d) 12/4/2018

Examples and ScreenShots (cont’d) Example 2: A sprite animation applet which allows the user to control the speed of the object by using up and down arrow keys, thus resulting in either of the two stages: crashing or landing safe. Fuel is set to a value of 50 which means when the user presses the up arrow key, the fuel starts decreasing. Speed increases as the object moves towards bottom. See the screen shots of this example in the next slide. 12/4/2018

Examples and ScreenShots (cont’d) 12/4/2018

Examples and ScreenShots (cont’d) 12/4/2018

References Xiaoping Jia “Object-Oriented Software Development Using Java”, Second Edition, Copyright 2003 A Gentle Introduction to Java Programming, http://progzoo.net/ht60GUI/020Animation.xml Object Oriented Systems A Simple Animation, http://vip.cs.utsa.edu/classes/cs4773s98/notes/cs4773.topic06.html 12/4/2018