-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a method to address a single sprite other than the name given in the spritemap? #1194
Comments
Calling The example is just showing two different ways of calling the method. (The first passing the exact position/dimensions in tile coordinates, the second passing a predefined sprite name.) |
Thank you. |
How should I refer to this when defining the element?
Does not work, so I've used
But FullDeck is only a name mapped to Not sure if this is the source, but there winds up being a downline problem:
Please advise? |
I think this is the root of your confusion here -- it looks like you're thinking of If you're testing in a browser, you might want to invest some time in learning how the debugging tools work -- by stepping through the code you'll be able to see that So although conceptually you can think of a sprite's location as being identified by either a name or a tuple of coordinates, since a tuple isn't a construct in javascript, you need to pass in either a // ok
e.sprite('name');
// ok
e.sprite(1, 4);
// doesn't do what you want -- you're passing one argument,
// and javascript doesn't support tuples like this
let actual = (1, 4)
e.sprite( actual );
// Need an object to refer to multiple values together
let actual = {r: 1, c:4);
e.sprite(actual.r, actual.c); (There are some tricks you can do by invoking
When you create a sprite map, under the covers Crafty generates a new component for each named sprite in the map. (You can see that each such component has the same initialization method, since they all use the same asset -- the only difference is the initial coordinate.) |
I've got a spritesheet with playing cards, row = suit, col = value.
Is there a built-in function/method to call up a single sprite from the sheet by coordinate? so that say
map[3,1]
would be the 3 of Clubs at the sprite location 4th row, 2nd col?The example at Sprite.sprite seems to be used to rename the sprite at that coordinate position, so I was looking for a related function to get/show a sprite.
The text was updated successfully, but these errors were encountered: