i'm trying parallaxa site to snap to certain point.
if ($(this).scrollTop() < 6500 && $(this).scrollTop() > 7500 ) {
$(this).scrollTop(7000);
}
But with these code the snapping occures even, when i wanna move out from area.
How to fix this?
Related
So I made a game, made a map, and everything is working fine. The problem is I made a very dumb collision system that worked first, but I am running into problems.
I am using player's X and Y positions to draw character, and using players tileX and tileY (x/32 and y/32) to detect collision. Heres a picture which explains my problem:
The Red box is players tileX and tileY cordinate.
Player still moves beyound the wall where the collision should happen.
The TileX doesnt let increases/decreases happen if they collide with a solid tile, BUT player's X and Y (sprite) still moves beyond that box for 31 more pixels. I have no idea how to fix this. My player image is not centered, its drawn on the top-right corner.
This is the current code im using:
for i=1, #lsx_map1 do
if math.floor(player.fx/32) == lsx_map1[i] and math.floor(player.fy/32) == lsy_map1[i] then
player.speedx = 0
player.speedy = 0
print("COLISSION DETECTED ON "..player.x.." "..player.y)
else
print(colVar)
colVar = colVar+1
end
end
if colVar == #lsx_map1 then
player.x = player.fx
player.y = player.fy
end
lsx_map1 is the number of solid tiles, and colVar should equal to that number if collision doesnt happen. In case collision happens, that number doesnt increase by one, and then nothing happens. Ask for any more details you need if you want to help me but you need more information.
Any help or tips would be appreciated. Thank you.
I've been looking at Figure 7-3 in this sprite kit documentation: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html but it has left me pretty confused. They seem to give the same name to multiple things e.g., camera/character.
I am in the default SKScene, MyScene class. In initWithSize, I create a SKNode *myWorld, just like the documentation suggests. I then have a series of methods that add my background images to myWorld. Scrolling that works just fine, but what I want to do is stop the vertical scrolling when the bottom of the images in myWorld reach the bottom of the scene. For the life of me, I cannot figure out how to refer to the bottom of myWorld. For the bottom of the scene, I simply do
CGPoint sceneFarBottomSide = CGPointMake(0, -self.size.height/2);
where self.anhorPoint is set to [0.5, 0.5].
How do I refer to the bottom of myWorld?
The edge of myWorld is whatever you set it to be. In other words, myWorld is a node which isn't itself a view or a sprite. It's simply an object that contains sprite or shape children (for example, SKSpriteNodes or SKShapeNodes). When you are adding your sprites to myWorld, keep track of their position. Then use their position to define the "size" of myWorld. You can use this size information along with myWorld.position to know when the (bottom) edge of myWorld is coming up.
It ended up being extraordinarily easy to resolve. Thanks Andrey for pointing me to that Apple documentation on the Adventure game, that's what really tipped me off and cleared up some of my understanding. Here's the few lines of code to get the behavior I desired:
// Move world
if (monkeyPosition.y > 0 && monkeyPosition.x > 0) {
[myWorld setPosition:CGPointMake(-monkeyPosition.x, -monkeyPosition.y)];
} else if (monkeyPosition.y > 0 && monkeyPosition.x < 0) {
[myWorld setPosition:CGPointMake(0, -monkeyPosition.y)];
}
Hello in a game I'm making using lua in Marmalade Quick,I have run into a problem with the physics.
I have a normal downward y gravity and have some notes that is affected by that.
Now I want to add some objects that "fly" horizontally on the X axis but I can not get it to work.
so one of the notes looks like this:
sky2 = director:createSprite(dw, 40, "textures/tractor.png")
physics:addNode(sky2, {type="dynamic"})
sky2.physics:setGravityScale(0)
my first thought was to
just add the following to an update listener
if(gameplaying == true) then
sky2.x = sky2.x-2.5
unfortunately this does not work after the node has got added physics
then I was looking into using
sky2.physics:applyapplyLinearImpulse or sky2.physics:applyForce
I used it like this
sky2.physics:applyapplyLinearImpulse(-10, 0, -20, 40)
The problem here is that the node then correctly moves along the axis but it is spinnig around (torque effects)..
Is there away to stop this or what am I doing wrong,,
thanks..
Found out that the Marmalade Quick Documentation was wrong, and to not input both a px and a px value but just 0 so sky2.physics:applyapplyLinearImpulse(-10, 0) this will apply the impulse at the centre of mass and make it move straight.
How do I make a RTS camera so that when the mouse is at the edge of the window, it will move either left/right/up/down. I been trying to create an invisible box at the side of the screen so that when the mouse is at the box it will move the camera, but it still doesn't work. Please help!
Building upon what #Davor Mlinaric said, using the mouses x and y coordinates (which can be gotten from Mouse.GetState()), and testing whether those coordinates come in contact with the top, bottom and sides of the screen.
It would be a good start to set where those boxes will be something along the lines of:
GraphicsDevice.Viewport.Width/Height -/+ offset
Where offset is the amount of distance from the top,bottom or side.
Then test where the mouse position is, with a boolean.
boolean inTheZone = false;
//Bottom Box
if(Mouse.GetState().Y > GraphicsDevice.Viewport.Height - offset)
{
//Move camera in the y axis downwards (+).
inTheZone = true;
}
else
{
inTheZone = false;
}
and then the same for the 4 remaining sides.
Notice ive also used Y here, depending on how you set up the camera this may change to Z.
I hope this helps
In my app I have a small subview that I'd like to tether in the bottom right corner and allow to be moved only vertically for a fixed distance.
I have some code to allow it to be dragged, but no further constraints:
- (void)viewDragged:(UIPanGestureRecognizer *)gesture
{
CGPoint translation = [gesture translationInView:keyView];
// move view
keyView.center = CGPointMake(keyView.center.x + translation.x,
keyView.center.y + translation.y);
// reset translation
[gesture setTranslation:CGPointZero inView:keyView];
}
I've looked around on StackOverflow and tried a couple of ways, but the only one that worked didn't take into account diagonal movement, and I couldn't find anything in regards to tethering it to one spot.
So does anyone know how this can be done? Many thanks
EDIT: Also, does anyone know of a good, informative reference doc (other than the Apple one) for topics of this nature?
can you just add in a line to the view dragged code that says if keyview.centre.y is less than some threshold (where you want it to stop), then don't change it below that. eg.
keyView.centre = CGPointMake(keyView.center.x,
keyView.center.y - translation.y < threshold ? threshold : keyView.center.y);
also remove the change to the x parameter to stop it moving diagonally.