Touches on the far left side not registering due to 3D Touch App Switching - ios

Since iPhone6s, when Apple introduced 3D Touch, they added a new way to switch apps : press down on the side of the screen, and swipe.
An annoying side effect is that this has introduced a small "dead zone" on the far left side of the screen. This can lead to missed input, which makes a game that we're developing feel bugged. The user is actually touching the screen, but because he touches the side, nothing happens.
I've seen this happen in both Unity and buildbox (cocos) games. In single tap games, this is not really an issue, but in our upcoming game, the user has to press on the left and right sides of the screen with their thumbs, and it happens quite a lot that a touch doesn't register.
Is there any way to turn off this behaviour in a game?
EDIT : As requested, here's the code I use :
if (Input.GetMouseButton(0)) {
if (Input.mousePosition.x < Screen.width / 2f) {
leftDown = true;
} else {
rightDown = true;
}
}
This is called in Update, and the leftDown/rightDown variables are used in FixedUpdate.
I've also tried looping through touches, same result :
for (int i = 0; i < Input.touchCount; i++) {
if (Input.touches [i].position.x < Screen.width / 2f) {
leftDown = true;
} else {
rightDown = true;
}
}
Thanks!

Related

iOS build from Unity's physics behave differently on the phone

When i play the game in the editor window, everything works as intended. But when i build and play the game on the iPhone, my object bounces off of the screen. I set Physics Materials with 0 bounciness but i think this is something different.
This is the code that makes the cube jump around:
IEnumerator JumpAroundDelay()
{
while (true)
{
switch (direction)
{
case 1:
rb.velocity = new Vector2(0, 0);
rb.AddForce(new Vector2(10, 10), ForceMode2D.Impulse);
direction = 2;
yield return new WaitForSeconds(Random.Range(0.1f, top));
break;
case 2:
rb.velocity = new Vector2(0, 0);
rb.AddForce(new Vector2(-10, 10), ForceMode2D.Impulse);
direction = 1;
yield return new WaitForSeconds(Random.Range(0.1f, top));
break;
}
}
}
This is the cube's inspector window:
This is how i want it to behave
And this is how it behaves
As you can see somehow when the cube hits on its straight side on the walls, it bounces off violently. It doesn't do this in the editor or on an Android device. Only on iPhone. Anyone encountered something similar?
I tried everything from changing unity versions to manually adding non-bouncy Physics Materials to every object in the game. Nothing changed

Tile-based movement with Lance game engine?

I'm using Lance for a game where the gameplay area is a tiled map. When a player presses the left-arrow key, their character should move one tile to the left, etc. I tried two approaches, see below, but got neither to work.
Could either approach be modified to work with tile-based movement? Or is a third approach needed? Or is Lance not suited to this kind of game?
Approach 1: Adjust the player's position directly when a key is pressed. From my GameEngine class:
if (inputData.input == 'left') {
player.position.x -= 32;
player.angle = 180;
}
While this works well for a single player, it doesn't in multiplayer. When player A moves, their position is not updated on player B's screen.
Approach 2: Set the player's state when a key is pressed:
if (inputData.input == 'left') {
player.state = 'walkLeft';
}
Then add a postStep handler in the common GameEngine class. (Adding it to Player didn't work). This code turns the player (over many steps) to face 180 degrees and then accelerates the player in that direction:
onPostStep(event) {
let players = this.world.queryObjects({instanceType: Player});
players.forEach(player => {
if (player.state == 'walkLeft') {
if (Math.abs(player.angle - 180) > 2)
player.turnLeft(2);
}
else {
player.accelerate(1);
player.state = '';
}
}
})
}
With this approach, if a player presses the left arrow key, their angle changes as expected at first, but the acceleration and movement is erratic. Also, Player A's position appears different on their screen vs the screen of Player B.
The Spaaace demo is the base for my project, so my project uses the same bending, physics engine, etc.
The first approach is better. The Brawler game in the sample collection does exactly what you describe. You can look at the BrawlerGameEngine.js code in https://github.com/lance-gg/tinygames/tree/master/brawler
Make sure that the action is processed in the method
GameEngine::processInput(inputData, playerId)

XNA 2D camera with horizontal scrolling boxes and collisions

I've got and XNA 2D game which I've been making, but I'm having problems with it.
I've got boxes scrolling across the screen which my sprite is jumping over. The sprite is being followed by a 2D camera, and I fear that the camera is causing issues, as it's causing the scrolling boxes to stop half way across the screen instead of continuing, and also the number of lives are decreasing rapidly rather than one life when one collision occurs.
This is the code in which my sprite collides with the moving boxes
Rectangle fairyRectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
hit = false;
for (int i = 0; i < GameConstants.TotalBoxes; i++)
{
if (scrollingBlocks.boxArray[i].alive)
{
Rectangle blockRectangle = new Rectangle((int)scrollingBlocks.boxArray[i].position.X, (int)scrollingBlocks.boxArray[i].position.Y, scrollingBlocks.boxArray[i].texture.Width, scrollingBlocks.boxArray[i].texture.Height);
if (IntersectPixels(fairyRectangle, fairyTextureData, blockRectangle, blockTextureData))
{
scrollingBlocks.boxArray[i].alive = false;
hit = true;
lives--;
scrollingBlocks.boxArray[i].alive = true;
scrollingBlocks.boxArray[i].position.X = random.Next(GameConstants.ScreenWidth);
scrollingBlocks.boxArray[i].position.Y = 570;
}
}
}
And this is the update function in the scrolling boxes
public void Update(GameTime gameTime)
{
for (int i = 0; i < GameConstants.TotalBoxes; i++)
{
boxArray[i].position.X = boxArray[i].position.X - 5;
boxArray[i].position.Y = boxArray[i].position.Y;
if (boxArray[i].position.X < 0)
{
boxArray[i].position.X = randomno.Next(GameConstants.ScreenWidth) + 700;
boxArray[i].position.Y = 570;
}
Helper.WrapScreenPosition(ref boxArray[i].position);
}
}
I want them to start at the right hand screen and move all the way across to x = 0, but they're currently stopping around halfway at x = 400.
And finally this is where I'm drawing it all, with the sprite and the block
if (gameState == GameState.PLAYINGLEVEL3)
{
graphics.GraphicsDevice.Clear(Color.Aquamarine);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
backgroundManager.Draw(spriteBatch);
//scrollingBlocks.Draw(spriteBatch);
spriteBatch.DrawString(lucidaConsole, "Score: " + score + " Level: " + level + " Time Remaining: " + ((int)timer / 1000).ToString() + " Lives Remaining: " + lives, scorePosition, Color.DarkOrchid);
spriteBatch.End();
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, camera.transform);
scrollingBlocks.Draw(spriteBatch);
fairyL3.Draw(spriteBatch);
spriteBatch.End();
}
Thanks for any help!
From the code provided I can't tell much about how your camera works but my guess is that when you start the level your camera picks a new center point(rather than the original xna screen location)
In other words, the center of the camera may have pushed it back a bit, so what you think is position 0 of the screen may have been pushed forward to the middle of the screen making the boxes stop. I'd suggest looking at these camera tutorials http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/ or http://www.youtube.com/watch?v=pin8_ZfBgq0
Cameras can be tricky so I'd suggest looking at a few tutorials to get the hang out matrices and view ports.
As for the lives taking away more than one, It's because your saying "If this box is colliding with my player, take away lives." the computer doesn't know that you only want one taken away as long as it's colliding with the player its taking away lives, it will keep decrementing.
Hopefully this will give you some ideas :D

Swipe Gesture for iOS in Flash CS6

I'm creating an app for iOS (mainly) in Flash CS6 and I'm having a few problems with getting a particular page to work.
The layout is as follows: I have a movie clip that is 3 times the width of the stage with my content, with the instance name of txtContent.
On a separate layer, my Action Script (v3.0) reads as follows:
import com.greensock.*;
import flash.events.MouseEvent;
//Swipe
Multitouch.inputMode = MultitouchInputMode.GESTURE;
var currentTile:Number = 1;
var totalTiles:Number = 3;
txtContent.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
function moveLeft():void{
txtContent.x += 640;
}
function moveRight():void{
txtContent.x -= 640;
}
function onSwipe (e:TransformGestureEvent):void{
if (e.offsetX == 1) {
if(currentTile > 1){
moveLeft()
currentTile--
} else {}
}
if (e.offsetX == -1) {
if(currentTile < totalTiles){
moveRight()
currentTile++
}
}
}
stop();
When I test the movie, with a touch layer, the movie clip successfully moves left and right for each swipe, and does not continue to move too far in either direction, in effect ignoring any other swipes.
However, when I compile the IPA and test on the iPhone, only the first two "tiles" move (I can only see two thirds of the movie clip with swiping), as if I swipe to the third "tile" I cannot swipe back at all. No matter what I do, it gets stuck on that third section.
Is there a problem in my code that isn't registering properly in iOS?
FYI, I'm testing on an iPhone 3GS.
It was my own mistake - the final 'page' of the slides did not have a large background with the alpha set to 0% like the others, therefore to slide it back it would only work when holding the text (which was small). With the addition of the background, the movieclip is solid and therefore swiping the whole screen worked fine.

Blackberry Storm Emulator - TouchGesture events not firing, how to get a Swipe to work?

Been playing with the Storm Emulator and the 4.7 JDE, for the life of me I can't figure out how to fire gesture events in the emulator.
Below is the touch event code for the RIM sample app EmbeddedMapDemo. It seems straightforward enough, but touchGesture.getEvent() == TouchGesture.SWIPE never seems to register to true.
How can I register swipes in the Emulator? With my mouse I try doing left-click and drag but that does not seem to work.
/**
* #see Field#touchEvent(TouchEvent)
*/
protected boolean touchEvent(TouchEvent message)
{
boolean isConsumed = false;
if(_mapField.isClicked())
{
TouchGesture touchGesture = message.getGesture();
if (touchGesture != null)
{
// If the user has performed a swipe gesture we will
// move the map accordingly.
if (touchGesture.getEvent() == TouchGesture.SWIPE)
{
// Retrieve the swipe magnitude so we know how
// far to move the map.
int magnitude = touchGesture.getSwipeMagnitude();
// Move the map in the direction of the swipe.
switch(touchGesture.getSwipeDirection())
{
case TouchGesture.SWIPE_NORTH:
_mapField.move(0, - magnitude);
break;
case TouchGesture.SWIPE_SOUTH:
_mapField.move(0, magnitude);
break;
case TouchGesture.SWIPE_EAST:
_mapField.move(- magnitude, 0);
break;
case TouchGesture.SWIPE_WEST:
_mapField.move(magnitude, 0);
break;
}
// We've consumed the touch event.
isConsumed = true;
}
}
}
return isConsumed;
}
Pressing the left mouse button simulates clicking down the screen... the simulator (and also an actual Storm device, I think) won't fire TouchGesture events while you're clicking down on the screen.
What you want to do is hold down the right mouse button and drag, since the right mouse button simulates a screen tap, without click. This way, you should be able to get TouchGestures to fire.
It's a little hard to do a gesture on the simulator, you kinda have to move fast, but if you use the right mouse button you should be able to do it.

Resources