How to change filepath of Sprite
duyanh0612 opened this issue · comments
I want to change filepath of Sprite when I click to it (handle in game_logic). But it's not allowed because Sprite.filepath is READONLY.
So is there any way to do it?
No, it cannot be changed.
You can create a new sprite with the new filepath and start using it instead, if you like. This could look like the sprite was changing images in the game, even though on the back end you are now dealing with a different sprite.
Let me know if you have any additional questions!
I just created a minesweeper game using your library. The filepath change problem I have solved according to your suggestion.
But now another problem is that I can't read the doubleclick event to open all the squares around a square with a number.
So is there any way to do it?
And here is the link to my game
https://github.com/duyanh20200013/rust_minesweeper
@duyanh0612 Not a simple way, no. The way to detect double-clicks would be to keep track of recent mouse clicks and the times they occurred and store that information in the game-state, and then when you observe two clicks close enough, run your double-click logic.
It would likely be easier to simply look for a different kind of click (right, left, middle) or look for a click combined with a key modifier (like shift, ctrl, etc.)