HTML5 ProgLan HTML5 Making a Game on the Canvas Part 1.

Slides:



Advertisements
Similar presentations
Using Bitmap graphics Having looked at vector graphics in the canvas, we will now look at using bitmap graphics.
Advertisements

Robotics Coordinates, position, orientation kinematics. HTML5 reading file. Homework: Prepare for lab. Postings.
Neal Stublen Why Use a Canvas?  Flexibility… Use of drawing primitives (lines, arcs, text) Direct access to element display pixels.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Programming games More drawing. Text. Radian measure. Faces. Homework: Do your own drawings. Create index.html file. Upload work.
Programming games Reprise on dice game and alternative dice game Homework: [Catch up.]. Finish dice game.
CANVAS Fundamentals. What is Canvas? Canvas is a medium for oil painting. One of the earliest oils on canvas is a French Madonna from Canvas is.
Spring /6.831 User Interface Design and Implementation1 Lecture 11: Output.
Gil Megidish And I love writing / rewriting / reverse engineering games.
IT Engineering I Instructor: Rezvan Shiravi
Building a Basic Visual Analytics System Vitaveska Lanfranchi Suvodeep Mazumdar Tomi Kauppinen Anna Lisa Gentile Update material will be available at
Windows 8 Game development using HTML5 and JavaScript Martin Beeby Technical Evangelist
HTML, HTML5 Canvas, JavaScript PART 3 LOOKING MORE CLOSELY AT FULL BLOWN GAME DESIGN A PATTERNED BACKGROUND (CREATED WTIH LOOPS) WITH A MOVING OBJECT CHALLENGES.
Programming games Recap. Upload work (Filezilla, index.html). Drawing lines. Drawing stars. Homework: Drawing exercises.
Homework: Finish dice game.
CHAPTER 2 HTML & HTML5 II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Brent M. Dingle, Ph.D Game Design and Development Program Mathematics, Statistics and Computer Science University of Wisconsin - Stout HTML5 – Canvas.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
Canvas academy.zariba.com 1. Lecture Content 1.What is Canvas? 2.Including Canvas in your HTML 3.Commands in Canvas 4.Drawing Shapes with Canvas 5.Animations.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Creating Interfaces Defining users. College exercise. HTML5 drawing. Homework: Post or make comment on other postings on reflection on college exercise.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
Add an Image. index.html about.html contact. html contact. html.
CS 174: Web Programming October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Brent M. Dingle, Ph.D Game Design and Development Program Mathematics, Statistics and Computer Science University of Wisconsin - Stout HTML5 – Canvas.
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on your cannonball. Homework: Finish.
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Programming Games [Show Google Maps project.] Demonstrate more examples. Classwork/Homework: Decide on final project. Post proposal to moodle.
Creating Graphics for the Web Learning & Development Team Telerik Software Academy.
Programming games Show your virtual somethings. Demonstrate Hangman and Black Jack. Show credit card (or other form input & calculation) Homework: [Complete.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
HTML 5 Hands On By Rohit Ghatol
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Creating User Interfaces HTML5 video & audio. Role of video and audio. Homework: Complete your own [small/simple] HTML5 video and audio projects.
School of Computing and Information Systems RIA Animation, part I.
Programming Games Show slide show (on your site). Bouncing something. Video element. Bouncing video element. Bouncing video drawn on canvas. Bouncing video.
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
HTML5 – Completing Your Game Proglan HTML5 Part 3.
08 – Canvas(2) Informatics Department Parahyangan Catholic University.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
Game Design Practicum (CMPS 179) Summer 2012 Classes and Objects and the Canvas UC Santa Cruz CMPS 179 – Game Design Practicum courses.soe.ucsc.edu/courses/cmps179/Summer12/01.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
Programming games Show work on site. Work on slide show. Timed event for bouncing ball. Homework: [Finish slide show and upload to site.] Acquire a short.
Game Development with JS and Canvas 2D
That Gauge is COOL! 
What is a Function Expression?
CMPE 280 Web UI Design and Development September 14 Class Meeting
Internet of the Past.
CMPE 280 Web UI Design and Development September 12 Class Meeting
Canvas Notes
Programming Games [Show Google Maps project.] Demonstrate more examples. Classwork/Homework: Decide on final project. Post proposal to moodle. 1.
מדעי המחשב ורובוטיקה בחט"ב
מדעי המחשב ורובוטיקה בחט"ב
ISC440: Web Programming II Ch14: HTML5 Canvas
The Canvas.
Adding a paddle (1) We now have a code, which will run forever and just have a ball bouncing around the screen until we shut down the program. To make.
Drawing Graphics in JavaScript
Context of what we are doing.
HTML5 – Canvas JavaScript Simple Drawing
Graphics Canvas.
CSc 337 Lecture 20: Canvas.
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on animation project. Homework: Finish.
Programming Games Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Show project. Classwork/Homework:
JavaScript – Let’s Draw!
Programming games Reprise on dice game and alternative dice game
Javascript canvas graphics
Presentation transcript:

HTML5 ProgLan HTML5 Making a Game on the Canvas Part 1

More on the Canvas The next few sessions we will look at the HTML5 Canvas from the perspective of creating a Break- Out type game

Create the HTML document Break Out!

Create the Canvas The first thing we need to do is create an instance of the element so that we can start to draw on it. If you look in the source for this page, you'll see a declaration that looks like this:

Create a Circle //get a reference to the canvas Var ctx = document.getElementById("g ameboard").getContext("2d" );//draw a circle ctx.beginPath(); ctx.arc(75, 75, 10, 0, Math.PI*2, true); ctx.closePath(); ctx.fill();

Add Color var ctx = $('#canvas')[0].getContext("2d"); ctx.fillStyle = "#00A308"; ctx.beginPath(); ctx.arc(220, 220, 50, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); ctx.fillStyle = "#FF1C0A"; ctx.beginPath(); ctx.arc(100, 100, 100, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); //the rectangle is half transparent ctx.fillStyle = "rgba(255, 255, 0,.5)" ctx.beginPath(); ctx.rect(15, 150, 120, 120); ctx.closePath(); ctx.fill();

Movement var x = 150; var y = 150; var dx = 2; var dy = 4; var ctx; function init() { ctx = $('#canvas')[0].getContext("2d"); return setInterval(draw, 10); } function draw() { ctx.clearRect(0,0,300,300); ctx.beginPath(); ctx.arc(x, y, 10, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); x += dx; y += dy; } init();

Simplifying Coding //BEGIN LIBRARY CODE var x = 150; var y = 150; var dx = 2; var dy = 4; var WIDTH; var HEIGHT; var ctx; function init() { ctx = $('#canvas')[0].getContext("2d"); WIDTH = $("#canvas").width(); HEIGHT = $("#canvas").height(); return setInterval(draw, 10); } function circle(x,y,r) { ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); } function rect(x,y,w,h) { ctx.beginPath(); ctx.rect(x,y,w,h); ctx.closePath(); ctx.fill(); } function clear() { ctx.clearRect(0, 0, WIDTH, HEIGHT); } //END LIBRARY CODE function draw() { clear(); circle(x, y, 10); x += dx; y += dy; } init();

Bouncing against walls function draw() { clear(); circle(x, y, 10); if (x + dx > WIDTH || x + dx < 0) dx = -dx; if (y + dy > HEIGHT || y + dy < 0) dy = -dy; x += dx; y += dy; } init();

The game is incomplete