www.webdeveloper.com
Results 1 to 3 of 3

Thread: HTML5 Game

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    79

    HTML5 Game

    I'm building a game and whenever a player gets hit, it turns red so the user knows that the player was shot. The player would not die just yet since it has say 5 lives.
    So whenever the player gets hit, the vector just display for an instance but the problem is that it is behind the sprite (i.e image).

    How do I make it so it is in front of the sprite?
    Or is there a better way of doing this?

    Here's my code:
    Code:
    	
    Player.hit = function(){
       ... some code ...
       ctx.fillStyle = "rgba(255,0,0, 0.5)";
       ctx.fillRect(this.x, this.y, this.w, this.h);
    }

  2. #2
    Join Date
    Apr 2013
    Posts
    11
    It look like you are using canvas. Why not draw the sprite first, then draw Player.hit after.

  3. #3
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    79
    it is canvas
    I load the image first then I draw do the "fillRect" after but the image always in the fore-ground. Not sure how I can reverse this??

    I'm trying to do this:
    when a player gets hit it turns red for a second showing the user that the player was hit.
    If there's another way of doing this, I'm open for suggestion.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles