setFillColor() doesn't seem to do anything - What's missing here?

Hi,

This line of code seems to simply be ignored. I have a rectangle image sprite that I want to change colors when hitting the player. 

 

The rest of the code in this if statement is executed correctly so it looks like this line is skipped or not done:

 

 function newbadguy.sprite:collision( event ) 

    if(event.other.type == “player”) then

      event.target:setFillColor(255, 0, 0)        <------doesn’t do anything.

 

Someone suggested that it would not work if the target was masked. Is MTE masking anything?

 

Thanks in advance

MTE manages the color of sprites as part of it’s layer lighting system. You can disable this by setting lighting = “off” in your sprite’s setup table.

Dyson,

OK, I understand now. I would like to use your cool lighting features.

  1. is there a way to make the player sprite flash at the moment of being touched by a badguy? (I already have the collision function setup and giving damage)

  2. Where is the documentation on your lighting features?

Thanks

Layer lighting is controlled by Tiled layer properties. You can find these and other reserved Tiled properties in MTE Reserved Tiled Properties 0v910 HTML.htm, in among the rest of the documentation. At the moment the functionality is limited to setting the color/tint of each map layer.

A simple way to flash a sprite would be to change its color when the collision occurs and use a timer to change it back after a short delay. I drew up a quick example in CastleDemo using a touch listener in place of an enemy collision:

local flash = function(event) if event.phase == "began" then print("flash") event.target.lighting = false event.target:setFillColor(255, 0, 0) local unflash = function(object) object.lighting = true object:setFillColor(255, 255, 255) end local closure = function() return unflash(event.target) end local timer = timer.performWithDelay(100, closure, 1) end end player:addEventListener("touch", flash)

In this example a touch event changes the player sprite red and the timer changes it back to its original color. This will also work even if you don’t set lighting = “off” in the sprite’s setup table. 

MTE manages the color of sprites as part of it’s layer lighting system. You can disable this by setting lighting = “off” in your sprite’s setup table.

Dyson,

OK, I understand now. I would like to use your cool lighting features.

  1. is there a way to make the player sprite flash at the moment of being touched by a badguy? (I already have the collision function setup and giving damage)

  2. Where is the documentation on your lighting features?

Thanks

Layer lighting is controlled by Tiled layer properties. You can find these and other reserved Tiled properties in MTE Reserved Tiled Properties 0v910 HTML.htm, in among the rest of the documentation. At the moment the functionality is limited to setting the color/tint of each map layer.

A simple way to flash a sprite would be to change its color when the collision occurs and use a timer to change it back after a short delay. I drew up a quick example in CastleDemo using a touch listener in place of an enemy collision:

local flash = function(event) if event.phase == "began" then print("flash") event.target.lighting = false event.target:setFillColor(255, 0, 0) local unflash = function(object) object.lighting = true object:setFillColor(255, 255, 255) end local closure = function() return unflash(event.target) end local timer = timer.performWithDelay(100, closure, 1) end end player:addEventListener("touch", flash)

In this example a touch event changes the player sprite red and the timer changes it back to its original color. This will also work even if you don’t set lighting = “off” in the sprite’s setup table.