I move around a png with the analog,
I use a colorpixel detection for my collision,
I'm able to get it to stop when it hit the color but then i can't move , what must I do to get the analog stick to continu moving the png without passing the red zone (like an obstacle)
while true do
screen:clear()
analogS() --- analog function that I have ealier in my code
if bgC:pixel(x1, y1) == red then
move = false
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end
this is part of the code, where the pixel detection and stop happens
Last edited by my psprecious on Mon Feb 20, 2006 7:49 am, edited 3 times in total.
while true do
screen:clear()
analogS() --- analog function that I have earlier in my code
if bgC:pixel(x0, y0) == red then
move = false
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end
Thanx it's not that yet but it seems to be closer to my goal since I don't get stop, now it kind breaks and jump over but I think I might manage
except if got more great ideas like this one cause it really help the fact it doesn't stop totaly really helps me out now I feel I'm going somewhere, well the dot is hehe
I'm not sure exactly where your problem is. Can we see your analogS() function. Also, this is a more efficient way to code your loop. You don't need that variable.
while true do
screen:clear()
analogS() --- analog function that I have earlier in my code
if bgC:pixel(x0, y0) ~= red then
x1 = x0 ; y1 = y0
end
So, it stops you before entering the red area correct? If yes, the detection is working fine, its somewhere else in your code that is not enabling you to move. And you say you can't move at all once it reaches this red area. Like you can't move backwards. Does movement work perfect without reaching the red area? Is the x0/y0 your current position and x1/y1 the next position. It's hard to tell, at least to me, from just this code.
------------------------------------------
---------Function Analog Stick------------
------------------------------------------
function analogS()
pad = Controls.read()
dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x0 + dx / 64
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y0 + dy / 64
end
end
board = Image.createEmpty(480, 272)
while true do
screen:clear()
analogS() --- analog function
if bgC:pixel(x0, y0) == red then
move = false
--and
--analogS()
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end
board:clear()
board:blit(0, 0, bgC, 0, 0, bgC:width(), bgC:height(), false)
board:blit(x1, y1, dot, true)
screen:blit(0, 0, board)
screen.waitVblankStart()
screen.flip()
if pad:start() then break end
end
here's the entire code, now with x0, y0 in the pixel detection, it doesn't totally stop, but it's not what I'm trying to do I want it to feel the edge of the red zone, so been able to go around not teleport on the otherside like it does now
The problem is that it keep moves even if you have hit the red spot once. Suppose you run into it by pressing left. It won't actually display the new spot of your dot but it still moves the x0 and y0, so eventually it is past the red area and thats why it "jumps" over it. If you want it to go around it, you need to kinda "stop" the updating of the x0 and y0 positions. I might suggest making boolean variables like moveLeft, moveRight, etc that will tell you if you can move in a certain direction. Then in the analog stick function, only update a certain x or y if you can move in that direction. Like:
if analog pressed left and moveLeft = true then
updateX
...
etc
in your detection code, update the boolean variables based on direction pressed and if it hit a red area, etc
Ok what it was doing I pretty much understood, it's the analog part that was bugging me I think I was under the illusion that the analog couldn't do that
But now that you tell me I can control it like the d pad, this shouldn't be to hard
big thanx man someone sugested to detect pixel around I think that's when I got confuse
fattymc03 wrote:The problem is that it keep moves even if you have hit the red spot once. Suppose you run into it by pressing left. It won't actually display the new spot of your dot but it still moves the x0 and y0, so eventually it is past the red area and thats why it "jumps" over it. If you want it to go around it, you need to kinda "stop" the updating of the x0 and y0 positions.
This is kind of what I was suggesting with the fix I posted earlier. You need to get clear on what the different variables are being used for. If you decide that (x1, y1) is the current location and (x0, y0) is the location you are possibly going to move to, then you only need to fix your analogS() function to calculate the new position (x0, y0) based on the current position (x1, y1) plus the motion vector (dx/64, dy/64):
function analogS()
pad = Controls.read()
dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x1 + dx / 64
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y1 + dy / 64
end
end
but what I get is weird, what happens is the get stock on the red pixel and to move away I need to go the opposite way, if I go up and down even if there is no red pixel it stays there. (would be great for a spider man game)