I am working on a tic-tac-toe game in my computer science class using processing-java. In my program, on the far right side I have a status bar that states which player's turn it is, who won, and who lost. This status bar is also placed vertically, so in my code I am rotating it and although it is rotating properly, it is causing another problem. The status bar appears in a certain area on the game screen, but after one X or O is placed, it moves spots and I am unsure of how to fix this. After another piece is placed, it moves a second time, then a third and then finalizes its place in an area I do not want it to be. This is my code regarding the text and rotation.
void updateStatus(String status) { // function to update the status message
fill(0);
rect(statusX, sbh, width, height-1);
stroke(#FFFFFF);
strokeWeight(4);
line(statusX, sbh, statusX, screenH); // Status line
fill(255);
String fullStatus = "It is player "+status+"'s turn";
//String fullStatus = "It is player X's turn";
float statusTxtX = width*15/16, statusTxtY = height*2.5/7;
pushMatrix();
translate(statusTxtX, statusTxtY);
rotate(HALF_PI);
textSize(55);
textFont(mainFont);
text(fullStatus, 0, 0);
//textDraw(status, mainFont, height, 255, CENTER, CENTER, statusX, height*3/12, width, height*1/2);
popMatrix();
}
The problem is with text-aligns. There is one in the placing() function and one in the textDraw() function. When you disable those the text stays in the same location. However, this will mess up the X's and O's, so you'll need to do some work on tracing where what text-align is set.
As a more general tip (since you're learning): put your first focus on functionality. You could for example build TicTacToe using println() and the numpad as input. When the game mechanics work you can add a nice user interface. Doing both at the same time often makes messy code that is prone to errors that are hard to debug. I bumped into that wall plenty of times myself ;)
Related
Basically i wanted to make a raycast for jumping but for some reason the distance of the raycast is wrong and never changes and the position of it is so wrong i cant even seem to find it:
ray2D = Physics2D.Raycast(transform.position, -Vector2.up, .1f, GroundedLayers);
Debug.Log(ray2D.distance);
isGrounded = groundCheck();
Grounded layers do not include the player, distance always returns as 0, grounded is always false and the gizmos line only draws when i open the prefab and not at all in the scene:
here the distance is set to .1f but displays the same as 1f
(EDIT: ok so i checked and for some reason the raycast happens around 0, -1 even tho thats nowhere near the player transform?)
Try Vector2.down instead?
Alternative things to try:
Is the player in the scene the same as the prefab?
Increase the distance.
Add a new GameObject at the feet of the player, reference that in your script and call the Raycast from there.
Is ray2d a RayCastHit2d?
Are your ground object tags correct, including all grammer/caps?
Try outputting in debug, ray2d.collider.name to see what you're actually hitting.
If you're using a rigid body, try rigidbody2d. position instead of transform.position
Do you have the player selected in the hierarchy? This is needed to see the gizmos.
I found that the raycast was detecting an invisible trigger so i had to put it on another layer :)
I have been successfully building and running a Unity 2D game, but started receiving a Blue Screen during one of my operations. Specifically, when I close a popup and remove all of its child Game Objects, the entire Game Screen turns dark blue (the default background color of the main camera). The music for the game still plays and clicks are still registered if you click in the right area (I can still press the back button, just can't see it).
If I remove 1 gameobject, this problem doesn't come up. But once I have to remove 2 game objects, the entire screen turns blue.
This is my function for removing my game object in case it helps, which works perfectly when it comes to actually removing the gameObjects correctly (game objects to be removed are created from prefabs). I think the problem may be with the camera for some reason, but I have no clue as to why it happens on this function.
public void Remove(int index)
{
float toggleWidth = toggle.GetComponent<RectTransform>().sizeDelta.x;
DestroyImmediate(scrollSnap.pagination.transform.GetChild(scrollSnap.NumberOfPanels - 1).gameObject);
scrollSnap.Remove(index);
scrollSnap.pagination.transform.position += new Vector3(toggleWidth / 2f, 0, 0);
}
I don't receive any errors or warnings in the console. Just a blue screen once more than one GameObject is removed
EDIT:
Turns out my main Canvas's planeDistance was being changed from 100 to 3200. I still have no clue as to why this change occurred...but for anyone else having a similar issue with a dark blue screen appearing in the middle or start of their game, then please check the values your canvas and camera in the Inspector. Simply controlling the planeDistance did the trick for me!
Made a new scene next to the sample scene when i started my sprite learning game. Forgot all about that.
When I had to publish it, In the Build Settings, I had the wrong scene selected. So It published an empty scene instead of my game.
I solved it by putting game in 3d mode and realized that the camera is positioned very far from the sprites, just change the z-axis and again go to 2d mode.
Just Move your camera in Z-axis position, it could be too far from object or it is behind the object, you can also check it by 3D mode the check the object position and change it in positive and negative values.
I'm fairly new to Unity and not quite sure how to handle this problem.
I have two images, one has clouds on it (day) and one has stars on it (night). What I want to do is show the clouds in the top of my scene and the stars on the bottom. There is a ground object in the middle of the screen where the player will be walking on, this should be the dividing line between the two images. The ground however is not one straight line but can have height differences.
The "solution" I came up with is to use the ground object(s) to slice the images so it kinda serves as a dividing line. But not sure if this is even possible. Maybe I could do something with 2 different camera's or mask the images somehow.. (Just throwing my own thoughts in here as well) I'll be fumbling around with these things in between and try to keep the topic up to date with what I tried.
I put in an attachment to (hopefully) make it more clear.
Greets,
Lukie
attachment: https://imgur.com/a/lblJXPi
The first solution to my mind was preparing a tileset. If you're not going to design a different section every time. So if you're not going to do a computer design. You can do it yourself by adjusting the size.
You can also dynamically generate the stars with the -y axis of the ground object and the clouds with the + y-axis. You can use instantiate function
Example:
public GameObject clouds;
public GameObject stars;
// Start is called before the first frame update
private void Awake()
{
Instantiate(clouds, new Vector3(this.transform.position.x, this.transform.position.y + 3.625f, this.transform.position.z), Quaternion.identity);
Instantiate(stars, new Vector3(this.transform.position.x, this.transform.position.y - 3.625f, this.transform.position.z), Quaternion.identity);
}
Of course, the background design that you will use here must be sustainable.
Dynamic Background
I'm working on something and seem to be stuck. I'm trying to add text over a button in Processing, however, once I use the translate method, my text is appearing upside down. How I can I simply rotate it so that it appears normal? Here's what I have:
void setup(){
size(600,600);
background(255);
translate(20,500);
scale(1,-1);
line(0,0,0,475);
line(0,0,550,0);
fill(0,255,0);
rect(400,-50,100,40);
fill(0);
font = loadFont("TimesNewRoman.vlw");
textFont(font,24);
rotate(PI/2);
text("Compute",405,-30);
}
Your problem is not caused by the translate() function. It's caused by passing a negative value into the scale() function. Here's a simple program that shows your problem:
scale(1,-1);
text("hello", 20, -20);
(You should really get into the habit of testing your assumptions and trying to isolate the problem like this.)
The scale(1, -1); line is flipping everything vertically. I can't really imagine why you would want to do that, so the simplest option would be to get rid of that line.
If you really need your scale flipped, then you're going to have to flip it back before you draw your text.
I'm making a game similar to Mario. At the moment my character can walk left and right and cannot go further when it reaches the border. Now, I want the view to scroll when the character is x amount of pixels away from the border. It shouldn't scroll just horizontally, but vertically as well.
At the moment I have 1 class that extends cclayer. This class draws a sprite and blocks. I have searched where to go from here, but I haven't really found anything useful/up to date.
So would be great if someone has some tips.
Also, in the mentioned class I also create a box2d world with gravity. If I have to make multiple layers do I create multiple box2d worlds for each layer?
You can use CCFolow action. This follow a node. Example:
CCSprite * hero = CCSprite::create("hero.png");
CCLayer * gamelLayer = GameLayer::create();
CCFollow *follow = CCFollow(hero, CCRect(0, 0, 4056, 3062));
gameLayer->runAction(follow);
When you change position of hero, the gameLayer move too, but always we see on the screen fragment of CCRect(0, 0, 4056, 3062). In this situation you don't need to use Scrolview, but normal CCLayer.