Discord
Login
Community
DARK THEME

How to remove a specific sprite offscreen?

I started with MicroStudio secently and I'm trying to make a card game. I made sprites for the cards and somehow I managed to create a button that draw random cards and put it in your "hand" (five rectangles). Now I'm figuring out how to remove a card sprite when you click on it (when you "play" it) so I could call variables to fill the empty spaces with new cards, but I simply cannot.

Isn't it a simple function like screen.drawSprite but the opposite?

You can just stop drawing it like this:

cardIsNotPlayed = function()
    //check if the card have been played or not
end

if cardIsNotPlayed() then
    screen.drawSprite("card", x, y...)
end

But it can change based on how you are managing the cards

I tried, but it seems to not work. I use simple boolean variables to manage if a space in the hand is full or empty, so when I set the function with hand1 == true and then I use the if argument with the function, it doesn't stop drawing the sprite even when hand1 == false.

call

screen.clear()  

That clears all the sprites onscreen, I'm looking to clear only sprcific ones as an else condition for the drawing.

I guess it would help if you publish what you have done so far and post the link here. (Keep it unlisted!)

That's actually a great idea, here it is:

https://microstudio.io/i/Yotsugen_Eiji/shobu/

At the moment I'm using a black sprite to "simulate" that I deleted a sprite, but that could be a problem when I add a background. What I want is to really erase the card sprites, one at once and no matter the order they are clicked.

You don't need else the sprites will show only if if-statement is true
also you need screen.clear() at beginning or at the end of function in order to refresh screen

draw = function()
  screen.clear()
  if hand1 == true then
    screen.drawSprite(deck[card1],-90,-42,50)
  end
  if hand2 == true then
    screen.drawSprite(deck[card2],-45,-42,50)
  end
  if hand3 == true then
    screen.drawSprite(deck[card3],0,-42,50)
  end
  if hand4 == true then
    screen.drawSprite(deck[card4],45,-42,50)
  end
  if hand5 == true then
    screen.drawSprite(deck[card5],90,-42,50)
  end
  screen.drawSprite("drawcard",200,0,50)
  screen.drawRect(-90,-42,33,50,"rgb(105,43,12)")
  screen.drawRect(-45,-42,33,50,"rgb(105,43,12)")
  screen.drawRect(0,-42,33,50,"rgb(105,43,12)")
  screen.drawRect(45,-42,33,50,"rgb(105,43,12)")
  screen.drawRect(90,-42,33,50,"rgb(105,43,12)")
end

OMG it works! Thank you!

screen.clear() should work as you could call it on specifically the cards you wish to remove.

Do you mean, writing the sprite name and the x y coordinates within the parenthesis?

No I don't know what @Bobbb is talking about you cannot write sprite name and the x y coordinates in parenthesis it will just return error,
but you can call screen.clear() in else statement, however that's not recommended because it will clear whole screen multiple times thru out function
After some period of time it will be mess to handle because it will affect gameplay with blank screens because draw function is called upon as much times as possible.
In your case calling it 4 times isn't as bad but it's just bad practice in general...
Also you can change background screen color by adding rgb or hex in parenthesis.
For example screen.clear('rgb(255,255,255)') or screen.clear('#ffffff') will make bg color white.

Ooohh, I see. Thank you!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community