Jump to content

Move Sprite by Touch, with Joystick Image


paulmo

Recommended Posts

Here's an example. Please emulate touch in Chrome console and move box upward to see what's going on. (Device setting: Samsung Galaxy S, SII.) I want "two" to disappear for good when "box" hits "two." After box crosses new x coordinate defined in 2nd for loop (move left), "three" is generated. When box hits "three", I want "three" to disappear for good, etc. Thanks.

Edited by paulmo
Link to comment
Share on other sites

I want "two" to disappear for good when "box" hits "two."

I don't think you're checking for that, unless you're using code I haven't seen. The code you posted above is a for loop that always renders the box as long as box.y is less than 69, that's the only condition you're giving it. You're not checking if it has been shown and hit already, just box.y. You'll also draw it multiple times. If box.y is set to 19, then you draw the box 50 times because you put it in a loop (that's why I'm wondering why you're using a loop for that). You need to keep track of the game's state, how many boxes they've hit, which box to show, etc. You need to add state tracking.
Link to comment
Share on other sites

Posted example as requested so you could see it...code is pretty much there except for additional for loop (view source). You're right I haven't checked to see if objects have been hit already. If you try it online you'll see that for loops tell where box object is, and if it goes to a coordinate, another object is rendered, etc. Just Googling around, state tracking seems a big topic...how/where does would that apply here? Thanks.

Link to comment
Share on other sites

for loops tell where box object is

You're not using for loops correctly. Any loop is for running some code several times. If you want to check something you use an if statement, not a for loop.One option would be to keep an array representing box objects, where you could have properties like the X and Y position and whether or not it has been hit. You can update each object when the corresponding box gets hit, and you can loop through the array to find the next box that hasn't been hit.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...