Hi there.
I'm new to Gideros, so I decided I wanted to play around a little bit, to develop a better feeling for it. For this I'm coding a little cardgame. For each card I use this button class giderosmobile[dot]com/tools/button (this is a link, forum said I cannot post links, so I edited it)
To add a little eye candy, I rotate the player cards, so they look like you hold them in your hands. Here comes the issue: When I click on the marked green dot, not the "real" card gets active, instead the right card (it is colored thatswhy in a blue tone).
The Image is here: www2[DOT]pic-upload[DOT]de/img/34314920/issue.png (Again, sorry, forum doesn't let me post links)
I guess this would be correct, if the image wasn't rotated. But of course I want that the "diamonds 8" card gets clicked, when I tap on that marked position.
I have a card class, where each card looks like
local button_pushed = Bitmap.new(Texture.new("images/start_down.png"))
local startButton = Button.new(button_default, button_pushed)
-- ! --
self.mycard = startButton
-- ! -- |
Then I have a PlayTable class, it arranges the cards like following:
foreach card = actualcard.mycard:
card:setAnchorPosition(....)
card:setPosition(....)
card:setRotation(....)
card:setScale(....)
card:addEventListener("click", onPlayerCardClicked, card) |
This visually rotates the cards the right way, only the clickable area don't seem to rotate, like described.
Comments
You are right, this is a long standing gideros issue (and my fault). See here for the record: https://github.com/gideros/gideros/issues/170
in any case luckily it is a rectangular shape, so you can do globalToLocal of the event x,y values to the local of the bitmap itself and test if it is in the bounds.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Because your cards overlap you would need more code to determine which card is the correct card that was clicked, based on which card is topmost in the spread of cards.
Beside that, during my journey the last days exploring gideros I googled a lot. The most hits were more than 5 years old. Because of this I want to ask, is gideros still active and thus save to learn it in favor of, say corona or something else?
I get that gideros is free and opensource and really appreciate all the devs work, but of course I want to learn a future-safe framework.
also, don't give up on globaltolocal, it is really not hard, if you do not manage, then somebody might spend the time to write you a small example code.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
As far as Gideros vs Corona goes, in my opinion Corona has better infrastructure (website, documentation, tutorials) but, that's it. The only reason these things are better is that they have huge amounts of money and people to throw at these things. Gideros has a very small team who are trying their best. You can of course help wherever you feel you can too
By far the worst aspect of Corona is having to have an internet connection to actually compile your project. No internet.. no can compile! You can go Corona Native to get offline builds but I think there is a hefty price tag attached to that path. This isn't the case with Gideros.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
But the game has only one deck of cards? If so "unlimited" becomes 52 right?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://blog.hmil.fr/2015/02/hacking-funrun2-how-to-reverse-engineer-a-corona-app/
https://deluxepixel.com
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
However I just tested and using hitTestPoint() on a rotated sprite only determines that the touch happened within the sprites bounds, not the actual shape (ie the rotated rectangle).
- It is subclassed from Bitmap so you need to supply a Texture or TextureRegion when creating a new card.
- When creating a new card it get's the dimensions for its collision polygon from the dimensions of the Texture (or TextureRegion) supplied.
- Call setCardPosition(x, y) to position the card on screen.
- Call setCardrotation(angle) to set the cards rotation.
- Call containsPoint(x, y) to determine if x, y are inside the cards rotated rectangle.
Here is the class..
Here is the complete program:
@keszegh:
I tried your code, and added it to the generic button class (to the end of it). After adding it, the buttons don't seem to be clickable anymore at all. Although I've to admit, I don't understand your code or how it works, so I cannot fiddle around with it.
@antix:
Wow, thank you for your efforts, I need to test and understand it, I'll go to try it out now. But it seems that you "reprogrammed" the whole actual problem class.
So I tried your code, all works well if I just have one card, but if I have two card I have the issue that on each click on one of the cards, both get selected. I don't know why. I used your card class as it was and modified your Main.lua as follows:
So I am just playing with this a little more and am making some code to choose random cards from a deck and then once you have a bunch of cards, it can spread them out in an arc across the screen.
I have been pondering the overlapping cards and I think that the way to solve it would be to do something like this...
1. Spread the cards in the hand in an arc.
2. When the screen is touched, go through the list of cards (from left to right) and find the first one that the touch is inside (if any).
3. get a list of all other cards (to the right) that overlap (intersect) the first card.
4. check each card in that list and the last one that was touched should be the correct card.
Well this is my theory and I'll test it in the morning when I get up
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Another option would be to getChildIndex on the touched card.
http://docs.giderosmobile.com/reference/gideros/Sprite/getChildIndex#Sprite:getChildIndex
But this one would require that cards are placed inside another Sprite (on stage there may be something else in addition to the cards)
Press the reset button to reset the deck.
Press deal to deal a new random card.
Click individual cards (overlapping is handled) to select them.
Click discard to enter discard mode where you can select and discard multiple cards.
The Card class is essentially the same and there is a new class called Deck, which creates cards and manages them.
When created, Deck will load the default card TexturePack. You can load new packs as you like and update any currently visible cards with the new imagery.
EDIT1:
I updated the example and now you can drag and drop cards to re-order them.
EDIT2:
I have updated this for the final time and now it includes functionality to select and discard multiple cards.
Any questions just holler :bz
Likes: pie
Likes: antix