Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / sprite positions

Author
Message
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 9th Apr 2012 14:01
is there any code that can make a sprite stay where it is when it hits a a certain area even if other pices of code try make it move?

kirtnicholls
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Apr 2012 15:16
There are several options available to you, here's one. When the sprite enters the area you have defined, flag it as dead, or whatever you want it to actually be doing. Here is an example.

That code should (I haven't tested it), blip the sprite about until it's x and y hits within 0 and 20 pixels. After that it will see that it has been flagged dead (0 being alive, 1 being dead), and avoid running the movement code. You can do this sort of thing for all sorts of games, I use flags a lot myself.
Of course this will only work when the x,y is within the boundary, so from left to right you could overlap all of the sprite on the x axis, until it eventually gets to the left edge of the sprite. You can tweak that code to work from within the center point of the sprite, by using byoffset in the set and position sprite commands. You can also alter it to include the width and height of the sprite to be spot on also. Alternately you could use a hidden sprite and sprite collision instead.

kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 9th Apr 2012 20:04
whATS THE "SPRITEINFO [1]" DO

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 9th Apr 2012 22:38
i made this



so when one sprite is clicked instead of moving like the other sprites it must stay in that position

but

it doesnt always work, this piece of code seems to out do it and make the sprite move



kirtnicholls
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 9th Apr 2012 23:07 Edited at: 9th Apr 2012 23:14
Sorry to say this, but this code has no purpose

In effect it says
If the x position is 45 and the y position is 40
position the sprite so that the x position is 45 and the Y position is 40.
it is the same as writing


I don't get what you are trying to do
Quote: "
is there any code that can make a sprite stay where it is when it hits a a certain area even if other pices of code try make it move?
"

No

The other pieces of code have to be aware of the need to not move the sprite.

Even Vader's suggestions require some co-operation from the other code.

There is one way to work around it, but it's too horrible to consider.

You lose the sprite reference - then nothing will can ever move that sprite again.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Apr 2012 23:09
The sprite info array is just to save the state in. You could use a variable instead, but I assume you will be using more than 1 at some point.

The code above looks a little confused. If you want to stop a sprite when you click it, just set the sprite position to getspritepositionx(76), and the same for the y when you click it. On release just let the program position it again. At the minute, in the first example you are actually doing nothing at all by clicking the sprite. You could rem out the first 6 lines with no difference at all.

kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 10th Apr 2012 00:11
The reason that piece of code is there because Im maki a card game so when you press the deck it shuffles 10 random cars out, but because of that when you want 10 new cards it moves the cards that are in play an re-uses them hence the repotition. Basicaly I'm trying to stop cards that are in play from being used again.

kirtnicholls
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 10th Apr 2012 01:23 Edited at: 10th Apr 2012 01:24
Ah I see.

What you need to do then is - as Vader said - flag the cards as dealt when you deal them.

Have you done anything with user defined types yet?

I would suggest using a UDT to hold the cards. That way you can use a different field for each piece of information and they all go in one array.

Then to access them, it's like a normal array but with the field name at the end.

The code above will generate an array of cards, with values from 1 to 13 and suits from 1 to 4.

The first 13 will have suit 1
the next 13 will have suit 2
etc.

Within each batch of 13, the values got from 1 to 13

It also sets the .isOut field for every card to 0

You will have to change it to use whatever image source you use for the sprites.

Anyway, before you deal a card you look at card[ number ].isOut

If this is set to 1, then the card is already out.
As you deal a card, you set this to 1

You move the cards as you would before, but access the sprite using

card[ number ].sprite

number is between 1 and 52
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 10th Apr 2012 13:30
do i have to do this for each sprite?

kirtnicholls
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 10th Apr 2012 16:36 Edited at: 10th Apr 2012 16:39
In the example I gave, each entry in the array represents a card in a normal deck.

Each card ( or entry in the array ) has its own sprite.

To pick a card you would use a number from 1 to 52.

suppose you are dealing with card 10

To move the sprite for that card, you would use card[ 10 ].sprite.

This would be the same as moving sprites[10] in your old code.

When a sprite is picked

You go through the list of cards and check each sprite in the array to see which card was picked.

Now cardpicked holds the card that was picked (or 0 if none)

To see if that card has been dealt, you check the .isout field of the card array
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 13th Apr 2012 15:31
Thanks

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 13th Apr 2012 20:46
What's the difference between
Quote: "
"

And


Does it change anything?

kirtnicholls
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 13th Apr 2012 22:16 Edited at: 13th Apr 2012 22:20
No difference in practical terms.

The User defined type allows you to hold several things in a single array slot. The sprite reference is just one of several bits.

This way, you can store the value of the card, its suit and any other information in the same array as the sprite.

This is instead of using several arrays.

You should try to get away from the idea of thinking in terms of sprites and instead think in terms of cards.

Yes, each card has a sprite, but in a card game, its the card that drives the game logic, the sprite is simply used to display it.

Login to post a reply

Server time is: 2024-05-08 13:04:11
Your offset time is: 2024-05-08 13:04:11