My cocos2d ipad app loading properly in ipad. But after the default loading screen, it loads not in full screen.
#implementation IntroLayer
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
IntroLayer *layer = [IntroLayer node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init])) {
CGSize size = [[CCDirector sharedDirector] winSize];
CCSprite *background;
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) {
background = [CCSprite spriteWithFile:#"Default.png"];
background.rotation = 90;
} else {
background = [CCSprite spriteWithFile:#"Default-Landscape~ipad.png"];
}
background.position = ccp(size.width/2, size.height/2);
[self addChild: background];
}
return self;
}
-(void) onEnter
{
[super onEnter];
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[HelloWorldLayer scene] ]];
}
#end
Related
I am a newbie to QT but have a bit of experience with C++. this is my first project with Qt and QML.
I want to develop a program that lets the user draw on a canvas (see picture below) and I would like to calculate the area of each contour. I figured out how-to-draw on a canvas.
Example 1 Picture shows a Red rectangle which is the canvas area where the user will do a free-form sketch. The user draws the black free-form sketch.
Now I would like to calculate the area on the left and right contour. User will always only draw from one edge to another edge.
Below is another example of the free-form sketch. In the following sketch, I need to calculate the area of the three contours.
also, the contours can intersect with the same edge and other contour.
My question is, what is the best way to calculate the area of each contour?
should I use a contour detection algorithm or OpenCV?
any thoughts on how i should tackle this problem.
My initial thoughts are
start at canvas position (0,0) and start counting until I reach one point drawn by the user and repeat until I reach the end
After watching a couple of YouTube videos, I figured out the interaction between C++ and QML. now I can access the mouse position in C++. (see code below)
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QQmlContext>
#include "canvasarea.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QScopedArrayPointer<CanvasArea> canvasArea(new CanvasArea);
engine.rootContext()->setContextProperty("canvasArea", canvasArea.data());
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
main.qml
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Row {
id: colorTools
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: 8
}
property color paintColor: "#000000"
spacing: 4
Button {
text: "Clear"
onClicked: {
canvas.clear()
canvasArea.clearCanvas();
}
}
}
Rectangle{
anchors.fill: canvas
border.color: "#ff0000"
border.width: 4;
}
Canvas {
id: canvas
width: 640
height: 480
anchors {
left: parent.left
top: colorTools.bottom
margins: 8
}
property real lastX
property real lastY
property color color: colorTools.paintColor
function clear() {
var ctx = getContext('2d')
ctx.reset();
canvas.requestPaint();
}
onPaint: {
var ctx = getContext('2d')
ctx.lineWidth = 1.5
ctx.strokeStyle = canvas.color
ctx.beginPath()
ctx.moveTo(lastX, lastY)
lastX = area.mouseX
lastY = area.mouseY
ctx.lineTo(lastX, lastY)
ctx.stroke()
canvasArea.mouseCordinates(lastX, lastY)
}
MouseArea {
id: area
anchors.fill: parent
onPressed: {
canvas.lastX = mouseX
canvas.lastY = mouseY
}
onPositionChanged: {
canvas.requestPaint()
}
}
}
}
canvasarea.cpp
#include "canvasarea.h"
#include <QDebug>
CanvasArea::CanvasArea(QObject *parent) : QObject(parent)
{
}
void CanvasArea::mouseCordinates(int x, int y)
{
QPoint point(x , y);
userContourLocations.append(point);
qDebug() << "currentCursorPositon" << point;
}
void CanvasArea::clearCanvas()
{
userContourLocations.clear();
}
I'm recreating an Objective-C app in SwiftUI. In my old app, I have a full-screen background image that has a slide transition between several images. Here's the Objective-C code:
- (void)viewWillAppear:(BOOL)animated{
self.output.text = [self.output.text stringByAppendingString:#"viewWillAppear\r\n"];
[self resetCardReader];
self.creditCard = [[FWCCreditCard alloc] init];
_imageArray = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:#"Family on Beach.png"],
[UIImage imageNamed:#"Chinese Graduate.png"],
[UIImage imageNamed:#"New Car.png"],
[UIImage imageNamed:#"House Sold.png"], nil];
index = 0;
}
- (void)viewDidAppear:(BOOL)animated{
self.slideTransition = [CATransition animation]; // CATransition * slideTransition; instance variable
self.slideTransition.duration = 2.0;
self.slideTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
self.slideTransition.type = kCATransitionPush;
self.slideTransition.delegate = self;
self.slideTransition.subtype =kCATransitionFromRight; // or kCATransitionFromLeft
self.repeatingTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(slideShow) userInfo:nil repeats:YES];
[self.repeatingTimer fire];
}
-(void)slideShow
{
[self.BackgroundImage.layer addAnimation:self.slideTransition forKey:nil];
if (index < self.imageArray.count-1) // NSUInteger index; instance variable
{
index++;
}
else
{
index=0;
}
self.BackgroundImage.image =[self.imageArray objectAtIndex:index];
}
Here's what I have so far in SwiftUI. Can anyone give me some pointers on where to add the animation?
struct HomeView : View {
private var backgroundImages = ["Family on Beach","Chinese Graduate","New Car","House Sold"]
private var backgroundImageIndex = 0
#State private var backgroundImage = "Family on Beach"
var body: some View {
ZStack{
Image(backgroundImage)
.resizable()
.aspectRatio(contentMode: .fill)
.colorMultiply(Color(red: 0.09, green: 0.286, blue: 0.486, opacity: 0.8))
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)
OK, I got it:
import SwiftUI
extension AnyTransition {
static var rightToLeft: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
let removal = AnyTransition.move(edge: .leading)
return .asymmetric(insertion: insertion, removal: removal)
}
}
struct HomeView : View {
private var backgroundImages = ["Family on Beach","Chinese Graduate","New Car","House Sold"]
#State private var backgroundImageIndex = 0
#State private var backgroundImageNameEven = "Family on Beach"
#State private var backgroundImageNameOdd = "Chinese Graduate"
#State private var showImage = true
var timer: Timer {
Timer.scheduledTimer(withTimeInterval: 10, repeats: true){_ in
if(self.backgroundImageIndex < self.backgroundImages.count-1){
self.backgroundImageIndex += 1
} else
{
self.backgroundImageIndex = 0
}
if(self.backgroundImageIndex % 2 == 0){
self.backgroundImageNameEven = self.backgroundImages[self.backgroundImageIndex]
} else {
self.backgroundImageNameOdd = self.backgroundImages[self.backgroundImageIndex]
}
withAnimation{
self.showImage.toggle()
}
}
}
var OddImage: some View {
Image(backgroundImageNameOdd)
.resizable()
.clipped()
.colorMultiply(Color(red: 0.09, green: 0.286, blue: 0.486, opacity: 0.8))
.edgesIgnoringSafeArea(.top)
.aspectRatio(contentMode: .fill)
.animation(.basic(duration: 2))
.transition(.rightToLeft)
}
var EvenImage: some View {
Image(backgroundImageNameEven)
.resizable()
.clipped()
.colorMultiply(Color(red: 0.09, green: 0.286, blue: 0.486, opacity: 0.8))
.edgesIgnoringSafeArea(.top)
.aspectRatio(contentMode: .fill)
.animation(.basic(duration: 2))
.transition(.rightToLeft)
}
var body: some View {
ZStack{
if(!self.showImage){
OddImage
}
if(self.showImage){
EvenImage
}
Just add the following to any other element on the view to trigger the timer on view:
.onAppear(perform: {
let _ = self.timer
})
So I'm building a tabbed application and the design calls for a UINavigationBar on some of the app's pages. After adding the navigation bar to one of my tabbed ViewControllers, the color of the UITabBar changed from the color that it has been set to originally (bluish-green) to grey. I've tried setting the TabBar Background color in my AppDelegate (which works fine on all other tabs), I've tried setting it locally in the custom TabBar View Controller (does not affect the color at all), I even tried setting it in the specific View Controller itself. I've tried setting a runtim property as well to no avail. I'm at a loss of what to try next. I've posted the code and screen shots below.
AppDelegate.swift
import Firebase
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let myGreenBG = UIColor(colorLiteralRed: 43/255.0, green: 111/255.0, blue: 109/255.0, alpha: 1.0)
FirebaseApp.configure()
UITabBar.appearance().backgroundColor = myGreenBG
UINavigationBar.appearance().backgroundColor = myGreenBG
return true
}
...
TabBarViewController.swift
import UIKit
class tabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let myGreenBG = UIColor(colorLiteralRed: 43/255.0, green: 111/255.0, blue: 109/255.0, alpha: 1.0)
//self.tabBar.delegate = self
//Code to render the unselected images in the tab bar
tabBar.backgroundColor = myGreenBG
for items in 0 ..< tabBar.items!.count {
let tabItemIndex = tabBar.items![items]
tabItemIndex.image = tabItemIndex.image!.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
/*for tabBarItem in (self.tabBarController?.tabBar.items!)!{
if !(tabBarItem.
}
}*/
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
...
Correctly displayed
Incorrectly displayed
Any Advice or tips would be greatly appreciated!
Try below code to change UITabBar background color-
UITabBar.appearance().barTintColor = UIColor.black
Hope it helps!
I have a UIImageView that I draw a triangle on. Points "A" leftPost & "B" rightPost are always static and the same distance from one another. The "tip" or point "C" is determined by tapping on the UIImageView. While the image is in portrait mode, I have no problem recreating the UIImageView along with the coordinates of the tapped CGPoint.
However, I need to display the UIImage in landscape mode and represent the same triangle. How do I "rotate" my coordinates to achieve this? I am also implying that I am NOT rotating the screen from portrait and landscape. The app is always in landscape.
import UIKit
class ViewController: UIViewController {
let bezierPath = UIBezierPath()
let shapeLayer = CAShapeLayer()
#IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let shotGesture = UITapGestureRecognizer(target: self, action: #selector(shotOnNet))
imageView.addGestureRecognizer(shotGesture)
//Enable tapping on screen
imageView.isUserInteractionEnabled = true
}
func setupBezierPath(tip: CGPoint) {
let leftPost = CGPoint(x: 20, y: 50)
let rightPost = CGPoint(x: 100, y: 50)
bezierPath.move(to: leftPost)
bezierPath.addLine(to: rightPost)
bezierPath.addLine(to: tip)
bezierPath.close()
}
func setupShapeLayer() {
shapeLayer.path = bezierPath.cgPath
shapeLayer.fillColor = UIColor.red.cgColor
shapeLayer.lineWidth = 1.0
shapeLayer.strokeColor = UIColor.black.cgColor
}
func shotOnNet(_ sender: Any) {
let shot = (sender as! UITapGestureRecognizer).location(ofTouch: 0, in: imageView)
setupBezierPath(tip: shot)
setupShapeLayer()
imageView.layer.addSublayer(shapeLayer)
}
}
I tried to create UITabBarController programmatically, but I have a SIGABRT when I click to tabBarItem.
Source:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
tabBarController = [[UITabBarController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] init];
UIViewController *vc2 = [[UIViewController alloc] init];
UIView *v1 = [[UIView alloc] init];
UIView *v2 = [[UIView alloc] init];
vc1.title = #"vc1";
vc2.title = #"vc2";
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
self.view = tabBarController.view;
}