contactTestBitMask works in general but if the graphic is too complex contactTestBitMask freaks out and you have only a small contact area or get weird errors. What can i do there?
This is an image about my area:
class GameScene: SKScene, SKPhysicsContactDelegate {
let WallCategory : UInt32 = 0x1 << 1
let ShipCategory : UInt32 = 0x1 << 2
var counter = 0
var userCanBuild1Building = false
var KameraSichtVar:SKCameraNode = SKCameraNode()
var touched:Bool = false
var startTouch = CGPointMake(0, 0)
//------------------------------
var draufgeklickt:CGPoint = CGPoint()
var draufgeklicktUpdate:CGPoint = CGPoint()
var userWantScroll = false
var userWantBuild = false
let wohnhausBlue = SKSpriteNode(imageNamed:"wohnhausBlue")
let buildMenu = SKSpriteNode(imageNamed:"Buildmenu")
var hitDetected = false
let actualBuilding = SKSpriteNode()
var userWantUpgrade : Bool = false
//var theBuildingBefore = SKSpriteNode()
//var houseLvlSave : Int = 0
var uphausSave : String = ""
func didBeginContact(contact: SKPhysicsContact) {
var BuildingObject: SKPhysicsBody
var ClickObject: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask
{
BuildingObject = contact.bodyA
ClickObject = contact.bodyB
}
else
{
BuildingObject = contact.bodyB
ClickObject = contact.bodyA
}
// upgrade Building
let name = BuildingObject.node!.name
let HouseLvL: Int = Int(name!)!
if HouseLvL > 0 && userCanBuild1Building == true{
userCanBuild1Building = false
let touchedBuilding = SKSpriteNode(imageNamed: BuildingObject.node!.name!)
touchedBuilding.name = BuildingObject.node!.name
let name = BuildingObject.node!.name
var HouseLvL: Int = Int(name!)!
HouseLvL = HouseLvL + 1
let uphaus = String(HouseLvL)
let setSpriteTexture = SKAction.setTexture(SKTexture(imageNamed: uphaus))
let upSize = SKSpriteNode(imageNamed: uphaus)
let resizeHousewidth = SKAction.resizeToWidth(upSize.size.width, duration: 0)
let resizeHouseheight = SKAction.resizeToHeight(upSize.size.height, duration: 0)
touchedBuilding.runAction(resizeHousewidth)
touchedBuilding.runAction(resizeHouseheight)
touchedBuilding.runAction(setSpriteTexture)
touchedBuilding.name = "\(uphaus)"
touchedBuilding.position = BuildingObject.node!.position
touchedBuilding.zPosition = BuildingObject.node!.zPosition
touchedBuilding.userInteractionEnabled = false
let upgradedbuilding = SKSpriteNode(imageNamed: uphaus)
touchedBuilding.size = CGSizeMake(upgradedbuilding.size.width, upgradedbuilding.size.height)
touchedBuilding.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed:"\(uphaus)"), size: upgradedbuilding.size)
touchedBuilding.physicsBody?.categoryBitMask = WallCategory
touchedBuilding.physicsBody?.affectedByGravity = false
touchedBuilding.physicsBody?.dynamic = true
touchedBuilding.physicsBody?.collisionBitMask = 0
addChild(touchedBuilding)
BuildingObject.node?.removeFromParent()
ClickObject.node?.removeFromParent()
}
if HouseLvL == 0
{
ClickObject.node?.removeFromParent()
}
}`override func didMoveToView(view: SKView) {
/* Setup your scene here */
if let KameraSicht:SKCameraNode = self.childNodeWithName("Kamera") as? SKCameraNode{
KameraSichtVar = KameraSicht
self.camera = KameraSichtVar
}
physicsWorld.contactDelegate = self
self.physicsWorld.gravity = CGVectorMake(0, 0)
func addBG(){
let background = SKSpriteNode(imageNamed: "0")
background.name = "0"
background.anchorPoint = CGPointMake(0.5, 0.5)
background.zPosition = 2
background.position = CGPointMake(CGRectGetMinX(self.frame)+self.frame.width/4, CGRectGetMaxY(self.frame)-self.frame.height/4)
background.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed: "0"), size: background.size)
//background.physicsBody = SKPhysicsBody(rectangleOfSize: background.size)
background.physicsBody?.categoryBitMask = WallCategory
background.physicsBody?.affectedByGravity = false
background.physicsBody?.dynamic = true
background.physicsBody?.collisionBitMask = 0
self.addChild(background)
}
addBG()
let wall = SKSpriteNode(imageNamed:"1" )
wall.name = "1"
wall.zPosition = 10
//wall.xScale = 3
//wall.yScale = 3
wall.size = CGSizeMake(100, 100)
wall.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
wall.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed: wall.name!), size: wall.size)
//wall.physicsBody = SKPhysicsBody(rectangleOfSize: wall.size)
wall.physicsBody?.affectedByGravity = false
wall.physicsBody?.dynamic = false
wall.physicsBody!.categoryBitMask = WallCategory
wall.physicsBody?.collisionBitMask = 0
self.addChild(wall)
}
`
ok i found the solution. the problem was the weird behavior of the contactTestBitMask when you use this graphic.(it only detected a contact in a small area of the graphic). the reason for that is that the graphic have separated shapes (like the half ring and some other small stuff).
i connected all shape so that its only one shape and now everything works perfectly fine. also tried it with some other graphics and the behavior of contactTestBitMask is: if you have separated shapes in your graphic, contactTestBitMask take exactly one of the shapes and make it the contact area ...but the other shapes in your graphic will not detect a contact then...
Related
I want to switch the positions of the buttons when we press the toggle button. Buttons are repositioned randomly. I tried a lot but was not successful. So if anyone knows how but randomly
val btnOne = findViewById<View>(R.id.buttonOne) as Button
val btnTwo = findViewById<View>(R.id.buttonTwo) as Button
val posOneX = btnOne.x
val posOneY = btnOne.y
val posTwoX = btnTwo.x
val posTwoY = btnTwo.y
btnOne.x = posTwoX
btnOne.y = posTwoY
btnTwo.x = posOneX
btnTwo.y = posOneY
Yes, I found the solution
b4.setOnClickListener {
var arswap = arrayListOf<Button>(b1, b2, b3);
var randomPos: Int = 0;
fun swap(b1: Button, b2: Button) {
var tempPosition = Point(b1.x.toInt(), b1.y.toInt())
b1.x = b2.x;
b1.y = b2.y;
b2.x = tempPosition.x.toFloat();
b2.y = tempPosition.y.toFloat();
}
var totalItems: Int = 3; // total number of items
for (i in 0..totalItems/3 ) {
randomPos = ((Math.random() * arswap.size).toInt());
var randomItem = ((Math.random() * ((totalItems / 2) - 1)) + ((totalItems / 2) + 1));
swap(arswap[randomPos], arswap[randomItem.toInt()])
}
}
In a JetBrains editor, what is the shortcut (or trick) to duplicate a line on itself without breakline (not like Ctrl + D). In other words, I want to turn this:
constructor(obj: Schema$Car) {
this.brand =
this.id =
this.model =
this.photoBack =
this.photoFront =
this.photoInteriorBack =
this.photoInteriorFront =
this.photoSide =
this.seatCount =
this.year =
}
into this:
constructor(obj: Schema$Car) {
this.brand = obj.brand
this.id = obj.id
this.model = obj.model
this.photoBack = obj.photoBack
this.photoFront = obj.photoFront
this.photoInteriorBack = obj.photoInteriorFront
this.photoInteriorFront = obj.photoInteriorFront
this.photoSide = obj.photoSide
this.seatCount = obj.seatCount
this.year = obj.year
}
As you can see here http://allopensensors.com/profile/andreas/
the date on x-axis is nonreadable. I'd like to add a line break. How can i solve this?
AmCharts.ready(function () {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "http://allopensensors.com/amcharts/images/";
chart.dataProvider = chartData;
chart.marginLeft = 10;
chart.categoryField = "year";
chart.dataDateFormat = "YYYY-MM-DD JJ:NN:SS";
// listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens
chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
// categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "200"; // our data is yearly, so we set minPeriod to YYYY
categoryAxis.dashLength = 3;
categoryAxis.minorGridEnabled = true;
categoryAxis.minorGridAlpha = 0.1;
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0;
valueAxis.inside = true;
valueAxis.dashLength = 3;
chart.addValueAxis(valueAxis);
// GRAPH
graph = new AmCharts.AmGraph();
graph.type = "smoothedLine"; // this line makes the graph smoothed line.
graph.lineColor = "#d1655d";
graph.negativeLineColor = "#637bb6"; // this line makes the graph to change color when it drops below 0
graph.bullet = "round";
graph.bulletSize = 8;
graph.bulletBorderColor = "#FFFFFF";
graph.bulletBorderAlpha = 1;
graph.bulletBorderThickness = 2;
graph.lineThickness = 2;
graph.valueField = "value";
graph.balloonText = "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>";
chart.addGraph(graph);
// CURSOR
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorAlpha = 0;
chartCursor.cursorPosition = "mouse";
chartCursor.categoryBalloonDateFormat = "JJ:NN:SS";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chart.addChartScrollbar(chartScrollbar);
chart.creditsPosition = "bottom-right";
// WRITE
chart.write("chartdiv");
});
// this method is called when chart is first inited as we listen for "dataUpdated" event
function zoomChart() {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
// chart.zoomToDates(new Date(1972, 0), new Date(2200, 0));
chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
}
To make it readable, you can rotate the labels with custom angle. Try categoryAxis.labelRotation : 45
For Reference: http://www.amcharts.com/demos/column-with-rotated-series/
Hope it helps!
The output of my graph is really small, I can't really see the values at the x and y axis. Is there a way to change this, so the graph is bigger?
My code to output the graph is:
ZedGraphControl zc = new ZedGraphControl();
GraphPane pane = zc.GraphPane;
PointPairList list1 = new PointPairList();
LineItem curve1;
pane.Title.Text = title;
pane.XAxis.Title.Text = xAxisTitle;
pane.XAxis.Scale.Min = 0;
pane.XAxis.Scale.Max = 11;
pane.YAxis.Scale.Min = 1;
pane.YAxis.Scale.Max = 12;
pane.YAxis.Title.Text = yAXisTitle;
Int32 totalCount = ds.Tables[objectName].Rows.Count;
double[] xVals = new double[totalCount], yVals = new double[totalCount];
for (int i = 0; i < totalCount; i++)
{
xVals[i] = Convert.ToDouble(ds.Tables[objectName].Rows[i]["ntotal"]);
yVals[i] = Convert.ToDouble(ds.Tables[objectName].Rows[i]["isomonth"]);
}
list1.Add(xVals, yVals);
curve1 = pane.AddCurve("Temp curve", list1, Color.Green, SymbolType.Circle);
for (int i = 0; i < totalCount; i++)
{
TextObj t = new TextObj("Teest", curve1.Points[i].Y, curve1.Points[i].X);
t.FontSpec.Border.IsVisible = false;
pane.GraphObjList.Add(t);
}
curve1.Line.Width = 1.0F;
pane.GetImage().Save(outPutDestination, ImageFormat.Png);
pane.AxisChange();
GetImage() function gets the current size of the pane, so we just have to increase the size of the entire pane(i.e: dock & maximize the window & then use the method to get the image).
DockStyle currentStyle = zedGraphControl1.Dock;
var currentWindowState = this.WindowState;
zedGraphControl1.Dock = DockStyle.Fill;
this.WindowState = FormWindowState.Maximized;
zedGraphControl1.GetImage ().Save ( #"c:\Image_1.png" );
this.WindowState = currentWindowState;
zedGraphControl1.Dock = currentStyle;
How in the following JSON response can I check if uids is nil ?
{
height = 480;
pid = "F#dd705e6b96a6e894556c0db84870501e_d97383cc80238c38b8907d99690fa1c9";
tags = (
{
attributes = {
glasses = {
confidence = 97;
value = false;
};
smiling = {
confidence = 97;
value = false;
};
};
center = {
x = "60.83";
y = "75.21";
};
gid = "<null>";
height = "49.58";
label = "";
manual = 0;
nose = {
x = "76.21";
y = "77.16";
};
pitch = "-5.55";
recognizable = 0;
roll = "-0.45";
uids = ( // <<<<<========== UIDs Key
);
width = "66.11";
yaw = "-19.56";
}
);
url = "http://face.com/images/ph/a6e529853432599dad6da996746cb070.jpg";
width = 360;
}
When I try :
if ([[[[photo objectForKey:#"tags"] objectAtIndex:0] valueForKey:#"uids"] count] == 0)
It keeps returning FALSE all the time.
I'm able to access a lot of these keys successfully. But it's just this one key that's giving me issues.
Like, to access the url key, I am using :
[photo objectForKey:#"url"];
And it's working absolutely fine.
What am I doing wrong with the uids key ?