Phaser js: is it possible to add css to a sprite?
up vote
-1
down vote
favorite
I want to take a sprite from my Phaser game and add to it some CSS. Is it possible? I made researches but found nothing. I would like to add to my sprite this CSS:
img {
webkit-filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
background-color: lightcoral;
}
javascript css canvas phaser-framework
add a comment |
up vote
-1
down vote
favorite
I want to take a sprite from my Phaser game and add to it some CSS. Is it possible? I made researches but found nothing. I would like to add to my sprite this CSS:
img {
webkit-filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
background-color: lightcoral;
}
javascript css canvas phaser-framework
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I want to take a sprite from my Phaser game and add to it some CSS. Is it possible? I made researches but found nothing. I would like to add to my sprite this CSS:
img {
webkit-filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
background-color: lightcoral;
}
javascript css canvas phaser-framework
I want to take a sprite from my Phaser game and add to it some CSS. Is it possible? I made researches but found nothing. I would like to add to my sprite this CSS:
img {
webkit-filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
filter: drop-shadow(1px 1px 0 black)
drop-shadow(-1px -1px 0 black);
background-color: lightcoral;
}
javascript css canvas phaser-framework
javascript css canvas phaser-framework
edited Nov 11 at 4:42
Eray Balkanli
3,85741943
3,85741943
asked Nov 11 at 4:39
JuZDePeche
186
186
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
No, you cannot style a Phaser sprite with CSS.
However, if you're using an image for the sprite you could add the element to the page as an img
element and then apply CSS styling to it. But, it could not then be used within the game with that styling.
If you wanted to do this in Phaser one option would be to make a duplicate of the sprite and tint it and offset it from the original sprite so that it looks like a shadow.
There's a Sprite Shadow example for Phaser 2 that shows this in action.
var sprite;
var shadow;
var offset = new Phaser.Point(10, 8);
function create() {
shadow = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
shadow.anchor.set(0.5);
shadow.tint = 0x000000;
shadow.alpha = 0.6;
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
sprite.anchor.set(0.5);
game.input.addMoveCallback(move, this);
}
function move(pointer, x, y) {
sprite.x = x;
sprite.y = y;
shadow.x = sprite.x + offset.x;
shadow.y = sprite.y + offset.y;
}
Alternatively, you could update your asset to include the drop shadow, if it should always be present. That would generally be more performant than adding it programmatically.
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
add a comment |
up vote
0
down vote
No, style can't be applied to a phaser sprite as Phaser adds the sprite to a Canvas.
However, you can add the drop-shadow effect to a sprite using Phaser.
Please note that CSS doesn't works on the objects which are drawn over a Canvas (but you can still add CSS to a canvas or parent div)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
No, you cannot style a Phaser sprite with CSS.
However, if you're using an image for the sprite you could add the element to the page as an img
element and then apply CSS styling to it. But, it could not then be used within the game with that styling.
If you wanted to do this in Phaser one option would be to make a duplicate of the sprite and tint it and offset it from the original sprite so that it looks like a shadow.
There's a Sprite Shadow example for Phaser 2 that shows this in action.
var sprite;
var shadow;
var offset = new Phaser.Point(10, 8);
function create() {
shadow = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
shadow.anchor.set(0.5);
shadow.tint = 0x000000;
shadow.alpha = 0.6;
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
sprite.anchor.set(0.5);
game.input.addMoveCallback(move, this);
}
function move(pointer, x, y) {
sprite.x = x;
sprite.y = y;
shadow.x = sprite.x + offset.x;
shadow.y = sprite.y + offset.y;
}
Alternatively, you could update your asset to include the drop shadow, if it should always be present. That would generally be more performant than adding it programmatically.
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
add a comment |
up vote
0
down vote
accepted
No, you cannot style a Phaser sprite with CSS.
However, if you're using an image for the sprite you could add the element to the page as an img
element and then apply CSS styling to it. But, it could not then be used within the game with that styling.
If you wanted to do this in Phaser one option would be to make a duplicate of the sprite and tint it and offset it from the original sprite so that it looks like a shadow.
There's a Sprite Shadow example for Phaser 2 that shows this in action.
var sprite;
var shadow;
var offset = new Phaser.Point(10, 8);
function create() {
shadow = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
shadow.anchor.set(0.5);
shadow.tint = 0x000000;
shadow.alpha = 0.6;
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
sprite.anchor.set(0.5);
game.input.addMoveCallback(move, this);
}
function move(pointer, x, y) {
sprite.x = x;
sprite.y = y;
shadow.x = sprite.x + offset.x;
shadow.y = sprite.y + offset.y;
}
Alternatively, you could update your asset to include the drop shadow, if it should always be present. That would generally be more performant than adding it programmatically.
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
No, you cannot style a Phaser sprite with CSS.
However, if you're using an image for the sprite you could add the element to the page as an img
element and then apply CSS styling to it. But, it could not then be used within the game with that styling.
If you wanted to do this in Phaser one option would be to make a duplicate of the sprite and tint it and offset it from the original sprite so that it looks like a shadow.
There's a Sprite Shadow example for Phaser 2 that shows this in action.
var sprite;
var shadow;
var offset = new Phaser.Point(10, 8);
function create() {
shadow = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
shadow.anchor.set(0.5);
shadow.tint = 0x000000;
shadow.alpha = 0.6;
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
sprite.anchor.set(0.5);
game.input.addMoveCallback(move, this);
}
function move(pointer, x, y) {
sprite.x = x;
sprite.y = y;
shadow.x = sprite.x + offset.x;
shadow.y = sprite.y + offset.y;
}
Alternatively, you could update your asset to include the drop shadow, if it should always be present. That would generally be more performant than adding it programmatically.
No, you cannot style a Phaser sprite with CSS.
However, if you're using an image for the sprite you could add the element to the page as an img
element and then apply CSS styling to it. But, it could not then be used within the game with that styling.
If you wanted to do this in Phaser one option would be to make a duplicate of the sprite and tint it and offset it from the original sprite so that it looks like a shadow.
There's a Sprite Shadow example for Phaser 2 that shows this in action.
var sprite;
var shadow;
var offset = new Phaser.Point(10, 8);
function create() {
shadow = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
shadow.anchor.set(0.5);
shadow.tint = 0x000000;
shadow.alpha = 0.6;
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'hotdog');
sprite.anchor.set(0.5);
game.input.addMoveCallback(move, this);
}
function move(pointer, x, y) {
sprite.x = x;
sprite.y = y;
shadow.x = sprite.x + offset.x;
shadow.y = sprite.y + offset.y;
}
Alternatively, you could update your asset to include the drop shadow, if it should always be present. That would generally be more performant than adding it programmatically.
answered Nov 11 at 5:53
James Skemp
4,81284775
4,81284775
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
add a comment |
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
Didn't use this way. I decided to use sprite.tint instead of creating a new sprite for each of mine. Thanks!
– JuZDePeche
Nov 11 at 6:45
add a comment |
up vote
0
down vote
No, style can't be applied to a phaser sprite as Phaser adds the sprite to a Canvas.
However, you can add the drop-shadow effect to a sprite using Phaser.
Please note that CSS doesn't works on the objects which are drawn over a Canvas (but you can still add CSS to a canvas or parent div)
add a comment |
up vote
0
down vote
No, style can't be applied to a phaser sprite as Phaser adds the sprite to a Canvas.
However, you can add the drop-shadow effect to a sprite using Phaser.
Please note that CSS doesn't works on the objects which are drawn over a Canvas (but you can still add CSS to a canvas or parent div)
add a comment |
up vote
0
down vote
up vote
0
down vote
No, style can't be applied to a phaser sprite as Phaser adds the sprite to a Canvas.
However, you can add the drop-shadow effect to a sprite using Phaser.
Please note that CSS doesn't works on the objects which are drawn over a Canvas (but you can still add CSS to a canvas or parent div)
No, style can't be applied to a phaser sprite as Phaser adds the sprite to a Canvas.
However, you can add the drop-shadow effect to a sprite using Phaser.
Please note that CSS doesn't works on the objects which are drawn over a Canvas (but you can still add CSS to a canvas or parent div)
answered Nov 13 at 10:14
Rathore
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245898%2fphaser-js-is-it-possible-to-add-css-to-a-sprite%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown