1. About the disappearing sprite
You have already succeeded in getting a sprite to move up and down.
You did this by adding to its y position while down is held, and subtracting from its y position while up is held.
The screen is 240 pixels high.
For the disappearing sprite, just do some setup. Each time before you check for the condition it should appear on, set its y position to #$FE (A value larger than the screen's resolution).
Then check the condition you want it to appear on (like A button being pressed), and set its y position to something on screen (like #$80) only if A is pressed.
So... its y position starts at #$FE. And that will only change if the condition is true.
Code: Select all
Happens every frame: sprite's y pos is set to #$FE
Check if A is pressed.
if A is pressed, y becomes #$80.
else y keeps the value you set before. (So it would still be #$FE)
When A is pressed, it appears. When released, it disappears.
Get that working before continuing. It's important. If you still have trouble with it, ask about THAT. No collision detection until the disappearing sprite works. Easy stuff before hard stuff. The reason I want you to do this is so you have something that will immediately tell you when something is not working. The code on your paper can't work. The disappearing sprite would tell you why if you checked each condition with it.
Edit: #$24 is different than #24. When you put a $, that means the number is in hex. #$24 = 36. #$32 is 50.
Another thing is coding in general .I thought its set in stone, but i see that doing something like a collision can be done in may ways.
Absolutely. There are a millions way to get the same result in programing. It's the same with math. I want the number 4. 2*2, 2+2, 8/2, 9/3+1 etc. They all get 4.
The most important thing is that you understand what you're trying to do. If you do, you can find many ways to do the same thing and can choose which one is best for you instead of relying on a possibly confusing piece of code.
For exsample: #$32 is for a 4 sprites paddle but this should be #$24 because the top already takes 8 sprites ,i only need to add the bottum 3 rows.
I don't understand this. A 4 sprite tall paddle would be exactly 32 pixels tall. But the top doesn't already take up 8 pixels (I assume you meant pixels). The position you have represents a pixel, not a sprite.
Sprites actually have very little to do with it. Let's pretend they don't exist for a bit.
You know the X location of your object. You know the y location of your object. This point is the top left corner of your object. It is a single point. Adding a width value to the X location makes your object grow that many pixels bigger to the right of this point. Adding a height value to the Y location makes your object grow that many pixels pixels bigger below that point.
How many pixels wide do you want your paddles to be? 8? Then you add 8. But this can be ANY number. It doesn't have to be a multiple of 8 just because sprites always are.
How many pixels tall do you want your paddles to be? 32? Then you add 32. 24? Then you add 24?
Depending on how your code is written, you're right. You should add 1 less, but you should do it for BOTH axises not just one. It's also possible to add more and use different branches, but bleh. A pixel difference won't matter for your first routine. When you understand it you can make it perfect.
The sprites have nothing to do with your collision detection. They help the player see what's going on, but they just don't matter to the computer checking positions. You can write working collision detection code on a computer that displays no graphics.
So the fact that your paddle is made up of multiple sprites shouldn't affect what your collision detection is doing at all.
Forget the paddles. Forget the ball. Forget every sprite except the one that disappears and reappears.
You know 4 things about two objects.
1. You know each object's X position (Left side of the object).
2. You know each object's Y position (top of the object).
3. You know each object's Width.
4. You know each object's Height.
Now use your disappearing sprite.
I asked you earlier to make two sprites that move. One of those sprites will be object1. The other will be object2.
You add object1's width to object1's x position. Compare that to object2's x position. If it is less, then the sprite disappears. Otherwise, it appears.
That's the first step.