Legacy GM [SOLVED] Remove a subimage using GML?

G

Guest User

Guest
Hello!
I've been trying to remove a subimage from a 52 subimages sprite using GML, I've looked in the manual for a function to achieve it, but unfortunately no hope.

So, how I can achieve this using pure GML?

Thanks in advance!

[ Keep reading the thread for more information ]
 
Last edited by a moderator:
You can't do this directly. At runtime, all sprites are packed into texture pages, so the idea of deleting a single image wouldnt work.

What you could so, is create a surface, draw all the sub-images onto that surface, minus the one you want to remove, then use the command, sprite_create_from_surface() and sprite_add_from_surface()

http://docs2.yoyogames.com/index.ht...eference/sprites/sprite_add_from_surface.html

I would question what you need to do this for however, perhaps there is a better way if we knew what you are trying to achieve?
 

trg601

Member
What do you need this functionality for? Because I have a very convoluted and probably slow idea:
You could draw all the subimages you want to a surface and save that surface as a "_strip#.png" image, then load that as a new sprite with sprite_add or sprite_replace.

If you wanted something faster you could manually handle the drawing and just skip over certain frames.
 

RangerX

Member
I also wonder why you need to do this.
Can't you figure out what frame to use and change them by the "image_index" variable ??
 
G

Guest User

Guest
I am working on a Blackjack game and I have this code right here to initialize the deck of card
Code:
global.cards = ds_list_create(); // Create the deck ds list
ds_list_add(global.cards, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10); // Spades
ds_list_add(global.cards, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10); // Clubs
ds_list_add(global.cards, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10); // Diamonds
ds_list_add(global.cards, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10); // Hearts
It is a Blackjack game, and as you guessed, there is a sprite with 52 sub images, I want to remove the sub image when the dealer deals the selected card, for example the "7 Of Diamonds", I want to remove the "7" from the data structure and remove the "7 Of Diamonds" as well from the deck, so the cards won't mess up, such as picking the 6 diamonds when the dealer had dealt the 8 of diamonds, because you know, the deck had shifted to the back.

I've been working on this for weeks now, looking for a good answer, still, no hope.
 

RangerX

Member
Ok I see, it's not the sprite index that needs to be played with, its your data structure strategy that needs improvement.
I'd have to think about it before giving you the best way to do it though. Another poster with such experience will probably pop in the thread.
You basically need 2 information in your data structure or array. You need a card number and to know if it can be drawn again or not.
 
Last edited:
So, you are using the sub images to keep track of what has been dealt? While it could work, it doesn't seem like the most logical. Is there any reason you aren't just storing that data in an array or a list?
 
G

Guest User

Guest
@RangerX , take your time. It took me 2 weeks to go nowhere, basically because working on other mechanisms in the game and procrastination. I am checking the other data structures for this; It would've been hella easier if I were able to remove the sub image.

Anyway, I was thinking about creating 2 data structures; one that has the deck, and the other has the sub images, but the only bloody problem is that, indexes cannot be initialized by me, I mean the ds starts from 0 to the end-1, I was hoping if I can use associative arrays, which are not available in GM.

@DividingByZero , I don't think you understand what I mean, I don't use the sub images to keep track of the ds; I am using the sub images as a visual way for the player to see the card that had been dealt, a sprite with 52 cards.

You can play my first version of game -- Blackjack: Classic Twenty-One-- here https://www.games.bitrunade.com/Blackjack/

I am updating the game because I do not want duplicates, I do not want 2 cards with the same value and suit, that why I am popping them off the ds.
 
Just make 52 card objects, add them to a ds_list called "deck"

As each card gets dealt, remove the card from the ds_list "deck" and add it to the players hand. (I would use a ds* for each players hand so I can keep track of which cards they have)

Once the hand is over, move all the cards from the players hands to a ds_list called "discard"

Once all cards have been played, move them back from the discard list to the "deck" ds_list.
 

FrostyCat

Redemption Seeker
As everyone else has said, you have an improper data model. Instead of putting point values into your list (which aren't unique), put in the subimage numbers 0 through 51 instead (which are unique). Then upon drawing a card, use a script to derive point values from it:
Code:
///point_value_of(card)
return min(10, (argument0 mod 13) + 1);
 
G

Guest User

Guest
Just make 52 card objects, add them to a ds_list called "deck"

As each card gets dealt, remove the card from the ds_list "deck" and add it to the players hand. (I would use a ds* for each players hand so I can keep track of which cards they have)

Once the hand is over, move all the cards from the players hands to a ds_list called "discard"

Once all cards have been played, move them back from the discard list to the "deck" ds_list.
There are only 2 hands. The player hand, and the dealer hand and I do have separate ds for each one.

Are you sure about this? It is just, haha, weird to have 52 objects.

As everyone else has said, you have an improper data model. Instead of putting point values into your list (which aren't unique), put in the subimage numbers 0 through 51 instead (which are unique). Then upon drawing a card, use a script to derive point values from it:
Code:
///point_value_of(card)
return min(10, (argument0 mod 13) + 1);
I can't really follow what you're saying, you're telling me to make a ds_list with 52 values (0 through 51) then fetch the value using this script? what if I wanted the card to be unique? say, only drew once? Can you please explain more, it sounds interesting.
 

kupo15

Member
Yeah that would be a really bad way to go about it. The best way I can think of off hand would be to create one sprite with 52 subimages containing your deck. Create a ds_list called deck that has 52 slots with the contents contain a number from 0-51. Then when you draw a card you remove the first index from ds_list and read the number (0-51) that is in that slot. That that number is the card you picked up and that number references the image_index in the deck sprite.
 

FrostyCat

Redemption Seeker
I can't really follow what you're saying, you're telling me to make a ds_list with 52 values (0 through 51) then fetch the value using this script? what if I wanted the card to be unique? say, only drew once? Can you please explain more, it sounds interesting.
I am asking you to put 0-51 into your deck instead of card point values, so that when you draw, you get subimage numbers. When you draw a card, use ds_list_delete at the position you draw from so that you don't get it again, and use the script I showed you to get the drawn card's point value.
 
G

Guest User

Guest
I am asking you to put 0-51 into your deck instead of card point values, so that when you draw, you get subimage numbers. When you draw a card, use ds_list_delete at the position you draw from so that you don't get it again, and use the script I showed you to get the drawn card's point value.
WOW, I just tested the script and it is amazing, it even limits it to 10 ! Thank you so much @FrostyCat !

Thank you all for your help!

I will mark this question as solved once I finish the deck, just to check if any further questions are needed, but for now, I am sure it is solved ;)
 
Top