Xcode/Objective-C implementing a players turn toggle - ios

I'm new to the whole VCM programming structure and more specifically to objective-c.
Right now i'm working on an iOS app that is like the game "connect 4." This Xcode project is my practice project that i've been using to play around/learn how to make iOS apps so there are several files and lots of commented out code, so Ill try my best to provide the necessary content from my project.
App State:
Right now I have a 10x10 grid of blue square/buttons. I'm still in the early stages of implementing the functionality of the game. Rather than making each square its own button, I created 10 frames and 10 buttons. Each row is a single button, which is broken up into 10 squares.
I currently have the squares change their color to red and become disabled once clicked. If I click multiple times.. the squares turn red when pressed. Heres a screenshot example run:
What Im wanting to do:
I want to build off of what I have, but not exactly sure how to keep track of which "players turn" it is. For example.. I want the first clicked square to turn red, representing player1's move. I want the second click to turn the button, say green, representing player2's move.. then the next move will be player 1's move.
I know Ill have to make sure the button is/was ENABLED and valid before switching which players turn it is.
How should I go about doing this? This is more of a general question, but I'll provide needed code snippets if necessary. Thanks!

In your .h file add an integer (variable)
int Turn = 1;
In your .m file you can do:
if(Turn == 1)
{
// Player one is playing
Turn = 2;
}
else if(Turn == 2)
{
// Player two is playing
Turn = 1;
}

Related

Is it possible to change color of bottom horizontal line of iPhone X series within app?

is it possible to change color of bottom horizontal line of iPhone X series within app(inside app only)? my client is asking to change color of this line, and i am not able to find any related topic or solution.
Thanks.
No, I don't think it is. That's drawn by the system, and is not part of your app. Apple does not let apps change things outside of that app's "sandbox".
Edit:
I found a long article on the subject online:
https://medium.freecodecamp.org/reverse-engineering-the-iphone-x-home-indicator-color-a4c112f84d34
It seems it's called the "home indicator" and this author supports my suspicion that you can't change its color.
Edit #2
As Matt points out, the color of the home indicator changes automatically. The system has logic in it that tries to keep enough contrast between the home indicator and the area around it so that it's clearly visible. See the article I linked for more on that subject than you probably wanted to know.
You can only remove it:
override var prefersHomeIndicatorAutoHidden: Bool {
return true
}
The color is applied automatically.

Buttons in iOS app don't respond to touches around the edge of the screen

I'm relatively new to iOS development, but I'm having a go at working on some open source code for an old game that used to be pretty popular (Eden World Builder)
I've made quite a lot of progress in cleaning up the codebase, making small changes. But there's an issue I can't seem to fix. Every button in the game will not respond to taps around the edges of the screen. If a button is in the corner of the screen, you will have to tap towards the bottom of the button.
I've tried to move the buttons away from the edges, and they work, but that isn't practical for use. So there's something preventing the edges of the screen from registering button taps for some reason, and it doesn't seem to be anything to do with the button target areas themselves.
One thing I've noticed: This game is currently on the App Store, even though it hasn't been updated since 2015. In the App Store version (Which is built from the same code that I have) the issue doesn't occur. It must be something to do with building it in a newer version of Xcode, right?
Any assistance would be very helpful, this has been frustrating me for weeks now. Thanks
The answer to your first question is most likely either that your button is outside its parent view, or a gesture recognizer is interfering.
If a button extends beyond its parent views boundaries (or any of its higher parents' boundaries), it will still be visible as long as the parent doesn't have clipping enabled. The result is that you will still see the button, but it will only respond when touching the parts that are inside the parent view. You can find this visually by using Xcode View UI Hierarchy found in the Debug Navigator.
If it is gesture recognizers that interfere with your button, there are several solutions that might work. Several are described in the link you got from #Anbu in the comment.
The answer to your second question is that old apps are linked against old frameworks. Even if they run on the latest iOS version, they still pull in older versions of the framework, causing them to (mostly) continue work as before. This is done to keep compatibility with legacy code.
Try adding this to viewDidAppear
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let window = view.window,
let recognizers = window.gestureRecognizers {
recognizers.forEach { r in
r.delaysTouchesBegan = false
r.cancelsTouchesInView = false
r.isEnabled = false
}
}
}

OpenLayers3 - is it possible to combine modify/draw/select operations?

I've started using OpenLayers3 in my app, and so far, I have succeeded in creating working versions of:
a combined draw/modify page (based on the relevant example, draw-and-modify-features.js)
a combined select/modify page (based on the relevant example, modify-features.js)
In the case of (1), the ol.interaction.Modify instance specifies that it will work on the features inside an ol.FeatureOverlay instance:
var modify = new ol.interaction.Modify({
features: featureOverlay.getFeatures()
...
...and it is that ol.FeatureOverlay that holds all the new features drawn by the user.
In the case of (2), the ol.interaction.Modify instance specifies that it will work on the features inside the ol.interaction.Select instance:
var select = new ol.interaction.Select();
var modify = new ol.interaction.Modify({
features: select.getFeatures()
});
...and unless I am mistaken, this creates a hidden ol.FeatureOverlay that holds the currently selected feature - which is then edited.
However, I can't see a way to combine all 3 - i.e. a user-friendly way to allow a user to draw, select and modify polygons.
What I'd (ideally) want is the functionality of draw/modify, but the moment I hit and keep Ctrl pressed, the cursor is no longer working in "draw" mode, but in "select" mode, allowing me to select one of the existing polygons, and subsequently hiting Delete on the keyboard to delete it, or just edit its vertices with the mouse. As soon as I click outside all polygons, I return to draw/modify mode.
I did the naive test - that of adding an ol.interaction.Select to the interactions of the draw/modify Map instance - which lead to hilarious results :-) For example, upon finishing the drawing of a polygon (i.e. when I double-click to close it) it's also getting selected... and clicking anywhere (inside or outside polygons) just starts another new polygon edge, it never selects a pre-existing one - etc.
My only thought of a solution so far is... for me to implement a "VI emulation" :-) i.e. a "command" mode (that is, the select/modify state) and an "insert" mode (i.e. the draw/modify state) - and you chose what mode you are in from a "state toggle" button inside the map (custom OL3 control) or outside the map (normal HTML button) .
I am, however, looking for a better way, like the one I suggested with holding Ctrl...
Any ideas/suggestions most welcome.
I never found a solution combining all three modes. Since no answer came up, I might as well share that in the end, having a "modal" form of working (i.e. hitting a custom control - a map-internal button - to enter "Select Mode") is not that bad. I ended up with a "Select mode", a "Draw/Modify mode", and a "Measure" mode - selectable via map-internal buttons:
In the end, it turned out fine - in hindsight, having a "combo" mode would in fact present significant usability disadvantages.

AS3/Air Shift focus from one text field to the next in ios

I am using Flash Pro cs6, AS3, Air3.8.. And I am using textfield for input. I am trying to make it so when the user presses "Done" it shifts to the next field. I am finding conflicting information about this on all the forums, including this one. I did search but never found a fix..
I am definitely receiving the events, and I tried adding a line that identifies the keycode, which has confirmed it is receiving keycode 13. I actually made it put the keycode into the field I want the focus to shift to successfully.. It just refuses to put focus on that field..
The code I am using is stated in the docs that it will not work in iOS.. BUT it DOES work further along on the same page of script, as well as on two other ones... I have:
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyhandler);
function keyhandler(event:KeyboardEvent){
if(event.charCode == 13)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyhandler);
stage.focus = null;
stage.focus = nextTextField;
}
}
I tried that while adding the listener to the text field first, then changed it to the stage, neither work.. I tried "requestsSoftKeyboard" and several other ways I have seen posted that supposedly work in iOS, but they didn't work.. There are other functions that use the same stage.focus to null, followed by stage.focus to MyTextField and they work, but they are initiated by pressing a button on the stage, NOT a button on the soft keyboard. The code there that works is just a standard if statement:
if (TextField == "")
{
stage.focus=null;
stage.focus=TextField;
}else if (NextTextField == "")
{
stage.focus = null;
stage.focus = NextTextField;
}else if (TextFieldAfterThat == "")
{
stage.focus = null;
stage.focus = TextFieldAfterThat;
}
That continues through all fields and always goes to the right one with the soft keyboard open, cursor blinking, and ready to type.. every time. I know the listeners are received from the soft keyboard "Done" because a function to capitalize the words works, and when I added code to confirm the keycode it worked. I also have found access to that value using "charcode" AND "keycode".. I do not know what the difference is, but both returned 13 and neither worked for me..
There is another place I use the same code to make a TextField active and set the focus after the user presses a radio button, and those all work every time.
I am not sure what the difference is coming from pressing "Done" vs. pressing an object on the stage, but it refuses to set the focus with the done button.
Anyone have any ideas or made this work before?
I had success assingning focus to a StageText in iOS like this:
stageText.assignFocus();
StageText offers many advantages over TextField because it shows a native text input. The only disadvantage I know is that you can't use custom fonts.
Here's the documentation, and a tutorial.
I haven't experimented with the "Done" key, but I did what you are trying to achieve with "Enter" key and it worked. Also take note that in iOS the "Done" key is meant to hide the keyboard, so that could be why you are having these problems..
With component FPTextField you can listen to the event click DONE. In this video, compared StageText and FPTextField: http://www.youtube.com/watch?v=BKYaoLtEmCU
Use ane library FPNativeUI: http://flashpress.ru/blog/ane/native-ui/?lang=en

XNA loading/splash screen on game start

I'm trying to have a loading screen that pops up as soon as you run that executable that launches the game, whilst the game loads I want to display an image on the desktop much like how Gamemaker allows you to have a loading image.
I've had a brief look around and most people want an image to be shown whilst they load content which is not what I want, or perhaps it is... =P
My guess would be to set the game window borderless at the start, load the splash screen, draw it, then begin all the main loading (Specifically loading DirectInput through SlimDX takes a while). However would this support having a transparent/irregular shaped image? E.G if I wanted a borderless circle to be displayed whilst the game loads, would that be possible?
Thanks.
It's very simple. Just implement System.Threading and you're done.
Here's how it works, first add:
using System.Threading;
to the top of your class, then add the following things:
//the enum for state types
enum GameState
{
Loading,
StartMenu
}
//Init our gameState enum as variable
GameState gameState;
protected override void LoadContent()
{
gameState = GameState.Loading;
spriteBatch = new SpriteBatch(GraphicsDevice);
device = GraphicsDevice;
Window.Title = "Your Window";
//Other stuff that you had here before, now go in LoadGame()
loadingscreen = Content.Load<Texture2D>("loading");
Thread bgLoad = new Thread(new ThreadStart(LoadGame));
bgLoad.IsBackground = true;
bgLoad.Start();
}
public void LoadGame()
{
//Loading stuff here
gameState = GameState.StartMenu; //or GameState.Playing
}
and then put a loading texture in your Content Project
If I understand you correctly, you essentially want to have a window opened that is not full screen that also lacks the regular border and buttons that accompanies a window.
I can't test this but this should be a good start.
Here!
I would start by creating a bare bones Game1 class that can track an image and keep track of time for a timer.
Later you could add logic that actually tracks the loading of assets in the main program.
To start I'd just test it for a fixed time like 3 seconds.

Resources