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 / movement issue

Author
Message
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 7th Apr 2013 23:30
im trying to make a group of sprites move right left then down (i managed to do it with one) dont know how to. i have done this to get it to work


but line 7
Quote: "if ( GetSpritex ( sprites[1] ) > 20 )"
will only work for one sprite and using
Quote: "if ( GetSpritex ( sprites[1] ) > origionalx#[1] + 10 )"
,
Quote: " if ( GetSpritex ( sprites[1] ) > (origionalx#[1] + 10) )"
ect wont work whcih isnt helpful as i wish to make more sprites move but cant get the code to work first. can anyone help me please?

kirtnicholls
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th Apr 2013 01:26
If you have the lines as shown together, the first if statement may be setting the direction to 1 and then it is immediately picked up in the next.

You need to do each block independently and make sure that you have a sync cycle between.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Apr 2013 09:37
maybe using the setspriteoffset for each sprite first,
then all have the same position for setposition.
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 8th Apr 2013 13:49
Not quite sure what you mean kirtn14.

You only move one sprite because.. you do. sprites[1] is whichever sprite ID is saved at sprites[1]. If you wanted to move more you would have to loop through sprites[] in some way, say a FOR loop or WHILE or whatever you prefer.

Example:



My hovercraft is full of eels
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 8th Apr 2013 18:23
i am using 'for i = 1 to 4' but it isnt shown and i need to change the code as each sprite is in a different place but they all need to do the same movement whihc is why i need to find a way of workiung out if the sprite has moved '+10'from its origional position

kirtnicholls
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 8th Apr 2013 23:31
You could print everything you're trying to match in your IF statement to see what is actually happening, it might help.



If it's too fast put a sync() and a Sleep(milliseconds) after the print.

My hovercraft is full of eels
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 9th Apr 2013 00:45
thanks for the help, ive managed it now

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 9th Apr 2013 00:46
the finished product is this


and as you can see i have moved the 'dim' out of the do to make sure the value is fixed and i have then added a new sprite which does what it needs to when the main sprite hits certain possitions

kirtnicholls
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Apr 2013 17:08
Take your dim statement out of the for loop and define it as a float (which is what it would default to with the # at the end) since you are getting the sprite position and that is a float value.


And you don't show how the sprites array is defined and filled (is it dimmed as 2 and an integer?).

Array declarations should not be in loops of any sort, since that sort of redeclares it and might mess with the values.

You are mixing using the index 'i' and hard index values and it isn't clear if that is what you intend.

In the first 'if', you use the 'i' index in all cases. In the second 'if', you use the 'i' index to check the sprite against its original position but then use '2' as the index to store the current position of the sprite indexed with 'i'. Shouldn't the '2' be 'i' or the 'i' be '2'?

In the fourth if, you use '1' as the index in the logic and then 'i' as the index in the action. Shouldn't the '1' be 'i' or the 'i' be '1'?

It looks like you would get a very strange set of interactions with what you have.

And you need to set your logic up so that it doesn't set the direction variable one way and then sets it the other way almost immediately.

Keep in mind that you won't see the affects of any sprite changes until the next Sync(). You might only see the last thing done and there won't be any changes between operations on the sprite until the Sync(). So, setting a sprite in one location in one line and then checking to see if it is in that position a couple of lines later won't catch the new position because there was no Sync() call to cause the setting to 'take'.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 10th Apr 2013 23:26
ive now changed the code to

but only sprites[7] moved down.. why is this please?

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 11th Apr 2013 00:09
i stopped this by changing the code to

but sprites 1 and 18 keep moving to the left, i think the error is here

Quote: "
"


kirtnicholls
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Apr 2013 04:31
Move your dim statements outside of the for loops, you are confusing things. Arrays should NOT be defined within loops, it causes the memory to be reallocated each time (potentially) and may or may not keep all the values stored in earlier iterations of the loop.

And change the second 'if (direction [i]' to 'else if (direction[i]' so that you don't trigger based on having just set the direction[i] to 1 in the previous 'if '

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 11th Apr 2013 22:14
it doesnt work, i changed it and they just freeze and do nothing

kirtnicholls
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Apr 2013 22:36 Edited at: 11th Apr 2013 22:36
Did you move your array dim outside of the loop?

And I think I just discovered part of your problem.

The values you are storing (and I mentioned this before) for the positions of the sprites are floats. But you are storing them in integer arrays. So, your comparisons to original won't ever produce what you expect since the values stored in that will always be truncated to an integer value so your addition and subtraction of 0.03 will not really be affective.

So, move your array declarations outside of that first do loop and change your code like this:


I changed 'original' to 'original#' so that it was more obvious that it is a float value. And I changed '= original' to '<= original#' because you are dealing with float values and it is not uncommon for it to be difficult to get exactly the same value over time because of the way floating point values are represented within computers (and this has nothing to do with AppGameKit, it is a floating point precision thing across all platforms and languages).

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 11th Apr 2013 23:29
the array has been out of the loop for a while

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 11th Apr 2013 23:37
thanks

kirtnicholls
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 12th Apr 2013 04:05
Quote: "the array has been out of the loop for a while"

Not based on what you've been posting. But I'll take your word for it.

I think the issue comes down to using an integer array to hold and compare floating point sprite locations.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 12th Apr 2013 08:51
I agree with Ancient Lady. Try printing the values to the screen and you will see the problem.

You at least two variables for direction, not one. You need directionX and directionY. I would also story the increment/decrement values for x and y for each sprite in an array. That way they can be made to move in different directions at different rates.

Once you get all these values, a user-defined type is much clearer - or better still a C++ or Pascal class.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-05-01 09:58:55
Your offset time is: 2024-05-01 09:58:55