detecting gaps inbetween - creating game
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
detecting gaps inbetween - creating game
So i have the background scrolling along the card with gaps in between, and the character is to jump over the gaps. My problem is that at the moment, nothing happens if the character goes over the gaps, I am wanting to code so that it will fall off/disappear the card. I have a rough idea where i am going with this but it isnt working. something along the line of this?
what i have on my card scrolling across.
"bg1" "bg2" "bg3"
if image "character" is left of image"bg2" then move image"character" to the bottom of card id "1003"
end if
if image "character" is left of image"bg3" then move image"character" to the bottom of card id "1003"
what i have on my card scrolling across.
"bg1" "bg2" "bg3"
if image "character" is left of image"bg2" then move image"character" to the bottom of card id "1003"
end if
if image "character" is left of image"bg3" then move image"character" to the bottom of card id "1003"
Re: detecting gaps inbetween - creating game
Hi.
Firstly, you cannot use the "left" property that way, though, oddly, no error is thrown. Rather, unless I misunderstand, why not just:
if the left of image "character" < the left of image"bg2" then hide image"character" --see the dictionary under the property "left"
Just so you know, you can also set the loc of an object to a value offscreen, like "50000,50000". which might be in the next room.
Craig Newman
Firstly, you cannot use the "left" property that way, though, oddly, no error is thrown. Rather, unless I misunderstand, why not just:
if the left of image "character" < the left of image"bg2" then hide image"character" --see the dictionary under the property "left"
Just so you know, you can also set the loc of an object to a value offscreen, like "50000,50000". which might be in the next room.
Craig Newman
Re: detecting gaps inbetween - creating game
ahh okay.. i think there needs to be something in between.. because that line of code if i take out the hide character and replace it with stopGame(already coded for) then the entire thing just stops..
Re: detecting gaps inbetween - creating game
Do you mean this locks up:
if the left of image "character" < the left of image"bg2" then stopGame
StopGame is a handler somewhere, I assume. Does it do so as well from the message box?
Craig
if the left of image "character" < the left of image"bg2" then stopGame
StopGame is a handler somewhere, I assume. Does it do so as well from the message box?
Craig
Re: detecting gaps inbetween - creating game
yes, that is the code i tried and it didn't work out as expected. i could replace the "stopGame" with anything later on.. my main focus is getting the "character" to disappear once it detects the gaps somehow...I see no where round this, it seems impossible
the character is self is not moving at all except for when it is clicked on by the mouse it jumps (for it not to fall between the gaps, atm there is no effect when it goes over the gap). The process of the game is similar to "baby horse run"

Re: detecting gaps inbetween - creating game
Hi.
I don't understand what you are saying. So the handler does not lock up, it just stops without performing? And the "character" is not moving as you wish. How do you make it move? Not with the "move" command, I hope, since that is blocking and has to complete before anything else can happen. There are ways around this, sort of, but could that be your problem?
More information is needed...
Craig
I don't understand what you are saying. So the handler does not lock up, it just stops without performing? And the "character" is not moving as you wish. How do you make it move? Not with the "move" command, I hope, since that is blocking and has to complete before anything else can happen. There are ways around this, sort of, but could that be your problem?
More information is needed...
Craig
Re: detecting gaps inbetween - creating game
For my background the images are positioned and locked in place as i want them, leaving small gaps in between (for the character to fall into) i have the code working for the images to move across the card continuously. I don't want the character to move forward or anything, just up and back down when it is click on only by the mouse(which i have managed to code for).
I am wanting the character to detect the gaps somehow, currently i have the moving background, and the character is in a still position not detecting the gaps. I am wanting to code for the character to disappear/fall into the gaps.
If i open up my card the character is always going to be in the bottom left corner of the card, at first it is on the grass(the scrolling background) it needs to detect the gap in-between the two images as it scrolls across to the character
"image1" "image2"
I hope i made better sense, and someone can help me out please
thanks
I am wanting the character to detect the gaps somehow, currently i have the moving background, and the character is in a still position not detecting the gaps. I am wanting to code for the character to disappear/fall into the gaps.
If i open up my card the character is always going to be in the bottom left corner of the card, at first it is on the grass(the scrolling background) it needs to detect the gap in-between the two images as it scrolls across to the character
"image1" "image2"
I hope i made better sense, and someone can help me out please
thanks
Re: detecting gaps inbetween - creating game
Hi.
So if you have managed all this, you should be able to detect when item 1 of the loc of the character, which is its "X" position on the card, is at or near the middle of the space bounded by the right of one image and the left of the adjacent one. This has to be managed, since you only want to check adjacent images, not more distant ones, which might give a false positive. Write back if this is still not clear.
Craig
So if you have managed all this, you should be able to detect when item 1 of the loc of the character, which is its "X" position on the card, is at or near the middle of the space bounded by the right of one image and the left of the adjacent one. This has to be managed, since you only want to check adjacent images, not more distant ones, which might give a false positive. Write back if this is still not clear.
Craig
Re: detecting gaps inbetween - creating game
yes, that is exactly it but im unsure how to code it, I have tried different methods but my coding is not right and i keep getting different error messages...
Re: detecting gaps inbetween - creating game
So make three buttons. Place two of them sort of close together, but with a gap between. In the third button script do something cute like:
Hold down the option key and move the mouse over this button.
Now can you change this to give an alert when the button is between the other two?
Craig
Code: Select all
on mouseMove
if the optionKey is down then set the loc of me to the mouseLoc
put the loc of me
end mouseMove
Now can you change this to give an alert when the button is between the other two?
Craig
Re: detecting gaps inbetween - creating game
This sounds like a side-scroller game, where the character does not move but the background does. I think the easiest way is to use the "within" function to determine whether the character overlaps either of the images. You'll need to decide whether you want to count only the center of the character button or the edges. To just compare the center (the loc) then you can do this:
If you want to use only the edges of the button (so the entire character must be in the gap) then:
Both of these use the entire rectangle of the button as the test. If you only want to test the actual pixels of the character then there's a different way to use "within", but let us know.
Code: Select all
put the loc of btn "character" into tLoc
if tLoc is not within the rect of img 1 and tLoc is not within the rect of img 2 then -- in the gap
jump
end if
Code: Select all
put the left of btn "character" into tLeft
put the right of btn "character" into tRight
put item 2 of the loc of btn "character" into tV
if tLeft,tV is not within the rect of img 1 and tRight,tV is not within the rect of img 2 then -- in the gap
jump
end if
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: detecting gaps inbetween - creating game
jacque wrote:This sounds like a side-scroller game, where the character does not move but the background does. I think the easiest way is to use the "within" function to determine whether the character overlaps either of the images. You'll need to decide whether you want to count only the center of the character button or the edges. To just compare the center (the loc) then you can do this:
If you want to use only the edges of the button (so the entire character must be in the gap) then:Code: Select all
put the loc of btn "character" into tLoc if tLoc is not within the rect of img 1 and tLoc is not within the rect of img 2 then -- in the gap jump end if
Both of these use the entire rectangle of the button as the test. If you only want to test the actual pixels of the character then there's a different way to use "within", but let us know.Code: Select all
put the left of btn "character" into tLeft put the right of btn "character" into tRight put item 2 of the loc of btn "character" into tV if tLeft,tV is not within the rect of img 1 and tRight,tV is not within the rect of img 2 then -- in the gap jump end if
Yes, this is exactly what i am looking for and it almost works perfectly..but because the scrolling background images is grass the actual image is quite high but you cant see how high exactly since it is grass if you can see what i am trying to say here... and so i think the pixel "within" code which you mentioned would be much better and come in more handy. Atm the character stops just at the edge of the image and not exactly in the gap. The user should be able to click on the character to whilst it is at the edge?
also the reason it stops is because i have added the code for everything to stop just to see what is happening..once everything is sorted the character will die off the screen somehow ...
Could you please tell me what the pixel is about and how i would come to coding it
thanks
Re: detecting gaps inbetween - creating game
The difference is just a variation on the syntax style. Use the parentheses version instead, like this:
But this may not be what you want. This form only checks to see if the location (tLoc) is over a painted part of the image. It will be false if tLoc is over a transparent area. If your grass image has lots of transparent areas, then this form could trigger anywhere on the card, not just in the gap. I think this would be less reliable than checking the boundaries of the image itself.
Code: Select all
if not within(img 1,tLoc) and not within(img 2,tLoc) then
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: detecting gaps inbetween - creating game
Here may be another approach.
Put an object ( like a button ) between the 2 images and make it not visible. Then just check for the intersection between your character and the object.
See if that works
Put an object ( like a button ) between the 2 images and make it not visible. Then just check for the intersection between your character and the object.
See if that works
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: detecting gaps inbetween - creating game
By the way, if the character is stopping at the edge it probably means you're using the first example I wrote. Try the second one, which will trigger only in the center of the gap.
The extra button idea could work too but it wouldn't act any differently than just calculating where the gap is, and would require scripting another moveable object.
The extra button idea could work too but it wouldn't act any differently than just calculating where the gap is, and would require scripting another moveable object.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com