HTML5 Tutorial – 43 – Animation for Games!

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

37 responses to “HTML5 Tutorial – 43 – Animation for Games!”

  1. Eden Avatar

    just being honest here: that the mouse isnt on the left top corner of the square has nothing to do with any error or failed attempt at the clientX/Y being correct; its the default margin html does for the body element. to correct it you need to subtract the position of the element(the canvas) itself froom the clientX/Y.

  2. Halil Bulduk Avatar

    Can't copy paste Bucky's code in 2017. We are in the future and most of this shit is changed. Here is a "useable" code. Probably better ways to do it. I am a noob. this is what I made.

    function doFirst(){
    "use strict";
    window.addEventListener("mousemove", bucky, false);

    }
    function bucky(e){
    "use strict";
    var x = document.getElementById('canvas');
    var canvas = x.getContext('2d');
    canvas.clearRect(0,0,x.width,x.height);
    var xPos = e.clientX;
    var yPos = e.clientY;
    canvas.fillRect(xPos -50,yPos -50, 100,100);

    }

    window.addEventListener("load", doFirst, false);

  3. BerlinerTourGuide Avatar

    how is the variable e = event being declared and filled? should it not be: (var) e = window.addEvent…. or something like this – before it is being passed into the func?? or is it, as the next tutorial suggests, somehow predeclared and automatically filled? thanx!

  4. Anam Amer Avatar

    can any1 tell me how to hide the cursor so that the black box acts as the pointer i can't seem to find any information about it on the web

  5. RustinPieber Avatar

    How is the e working when it didn't even got passed in as parameter!?

  6. sanat Avatar

    difference between clientX and pageX?

  7. SomethingLikeThis Avatar

    All the tutorials so far, worked without any trouble.

  8. Jay Pretli Avatar

    Can anyone get this to work as of this date?

  9. Davit Svanidze Avatar

    ==================== THIS WORKS ====================

    function doFirst() {
    var x = document.getElementById('canvas');
    canvas = x.getContext('2d');

    window.addEventListener("mousemove", svanski, false);

    }

    function svanski(e) {
    canvas.clearRect(0, 0, 600, 400);
    var xPos = e.clientX;
    var yPos = e.clientY;
    canvas.fillRect(xPos, yPos, 100, 100);
    }

    window.addEventListener("load", doFirst, false);

  10. Muresan vlad mihail Avatar

    IT CANT REPLACE JAVA 🙂

  11. James Zafar Avatar

    Can you show us the way to use a timer to make it move?

  12. Peristilo peris Avatar

    Variables are more flexible and could be used later on in many different ways in case the application gets more complex..

  13. IdkWhatsRc Avatar

    You're probably loading the image every frame instead of loading it once at the beginning.

  14. khaled touaibia Avatar

    maybe you use an old browser!

  15. カラス Avatar

    Why make those xPos and yPos variables when you can just simply type "canvas.fillRect(e.clientX-50, e.clientY-50, 100, 100);"?

  16. RLS0812 Avatar

    There is no way in heck HTML5 can replace Java or action script . Those languages have many powerful features that HTML5 can't even come close to.
    Even PHP has more "back end" features ….

  17. Cam Cole Avatar

    Because of the way this is written, it gets re-drawn each time the mouse moves. Sounds like your picture is being re-drawn every time the mouse moves too. Voila, flashing picture.

    I'm new to this as well, so I can't actually solve your problem. I know this is a 3 month old comment.. hopefully you figured it out on your own with time 🙂

  18. Alexey Ilin Avatar

    everything works good… untill u move the mouse wheel ( if the page is big enuf)
    when it happens mouse jumps below the Rect and keeps just like that ;

  19. Zed Avatar

    I put an image instead of rect, but when i move cursor image blinks/flashes. Why is that?

  20. Bart Sprengelmeijer Avatar

    because of the word game probably

  21. Turgut Arslan Avatar

    Hi Bucky i am trying to build a Simple Canvas Paint. İ can start a drawing event but i cant stop it. how can i do this?
    Here is my JScript code
    pastie org/5573200

  22. PetaroMitaro Avatar

    I typed this whole into one html and when i tested it nothing happened D: any reasons why it might have failed?

  23. RebornXSoldier Avatar

    @fogglee It's a burrito.

  24. Fiif Avatar

    @fogglee They wrk together, javascript is a great addition to HTML5,

  25. alchemication Avatar

    @fogglee These javascript functions only work in HTML5-compalible browser, never be afraid to ask questions…

  26. Dr Pein Avatar

    bucky please make environmental science videos

  27. Trevor Tenzin Avatar

    @iluismadrid Visit kirupa.com. There is a tutorial on the countdown timer. ; }

  28. Meister Solaire Avatar

    Hello i was wondering if you could please make a tutorial on how to make an HTML5 countdown timer to date because i can't find one in all youtube or the web and thank you for all your tutorials they really help me a lot.

  29. Andreas Lindhé Avatar

    Can I put the canvas in the background (or something like that) to give the user some mouse effects on specific parts of my website?

  30. Alexandre Turdzeladze Avatar

    PLEASE make more UDK tutorials!

  31. rovfitta Avatar

    Hi, I cant get this to work. Perhaps you can post the code somewhere to download. Maybe a link here or on your own website?

  32. fotelos Avatar

    man you posted the right video the right time.

  33. awesomelemonade Avatar

    why is this one the most views?
    or is it because of games

Leave a Reply to Davit Svanidze Cancel reply

Your email address will not be published. Required fields are marked *