logo
down
shadow

How to make a Sprite node spin when a user taps the screen? Swift 3


How to make a Sprite node spin when a user taps the screen? Swift 3

By : Koushik Jain
Date : November 21 2020, 11:01 PM
hope this fix your issue The result Im looking to achieve: I have a node that is pretty much a bicycle wheel with spokes. When the user tapes the screen, I would like the wheel to not only bounce, but to spin as well with each tap. , To have the SKSpriteNode rotating, add this to touchesBegan:
code :
wheelNode.run(SKAction.repeatForever(SKAction.rotate(byAngle: CGFloat.pi * 2.0, duration: 2)), withKey: "rotateWheel")
removeAction(forKey: "rotateWheel")


Share : facebook icon twitter icon
Making a sprite jump when user taps on the screen?

Making a sprite jump when user taps on the screen?


By : Samijoe
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am using andengine to implement a sprite being able to be dragged across the screen using this. , This should work:
code :
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
    if(pSceneTouchEvent.isActionDown()) { //Jump only if the user tapped, not moved his finger or something
        final Entity playerEntity = ...;//Get player entity here.

        final float jumpDuration = 2;
        final float startX = playerEntity.getX();
        final float jumpHeight = 100;

        final MoveYModifier moveUpModifier = new MoveYModifier(jumpDuration / 2, startX, startX - jumpHeight); // - since we want the sprite to go up.
        final MoveYModifier moveDownModifier = new MoveYModifier(jumpDuration / 2, startX + jumpHeight, startX);
        final SequenceEntityModifier modifier = new SequenceEntityModifier(moveUpModifier, moveDownModifier);

        playerEntity.registerEntityModifier(modifier);
        return true;
    }
    return false;
}
Trying to make my sprite jump when someone taps on screen using onTouchEvent(MotionEvent), but don't know how this metho

Trying to make my sprite jump when someone taps on screen using onTouchEvent(MotionEvent), but don't know how this metho


By : user2613349
Date : March 29 2020, 07:55 AM
To fix this issue You need to specify that onTouchEvent overrides the original method in Activity. You should also call super.onTouchEvent(e); at the end since the method you're overriding may need to execute.
code :
@Overrides
public boolean onTouchEvent(MotionEvent e) {
int i = e.getAction();

switch (i) {

case MotionEvent.ACTION_DOWN:
    // When your finger touches the screen
    p.jump();
    break;

case MotionEvent.ACTION_UP:
    // When your finger stop touching the screen

    break;

case MotionEvent.ACTION_MOVE:
    // When your finger moves around the screen

    break;
}

return super.onTouchEvent(e);
}
How do I make a node move in sprite kit swift

How do I make a node move in sprite kit swift


By : user2846728
Date : March 29 2020, 07:55 AM
like below fixes the issue To move a Sprite in Sprite-Kit you can use SKActions.
For example:
code :
let action = SKAction.moveByX(3, y: 2, duration: 10)
let action2 = SKAction.moveTo(location: CGPoint, duration: NSTimeInterval)
Sprite Kit (swift) node friction - screen jumping

Sprite Kit (swift) node friction - screen jumping


By : Pat Tinsley
Date : March 29 2020, 07:55 AM
hope this fix your issue Mass and damping can be problematic for characters. Here's how I would set up your player dynamics for jumping:
code :
physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.size.width, self.size.height))
physicsBody?.dynamic = true
physicsBody?.allowsRotation = false
physicsBody?.restitution = 0.0
physicsBody?.friction = 0.0
physicsBody?.angularDamping = 0.0
physicsBody?.linearDamping = 0.0
physicsBody?.affectedByGravity = true
physicsBody?.applyImpulse(CGVector(dx: 0.0, dy: 50.0))
Swift allow user to choose player Sprite Node

Swift allow user to choose player Sprite Node


By : Phuc Nguyen Trieu
Date : March 29 2020, 07:55 AM
help you fix your problem Although I'm not entirely sure how to interpret your question, here goes!
I would recommend creating a bit of logic to allow you to insert the avatar in the selection scene, as well as your game scene.
code :
extension SKSpriteNode {
    enum AvatarType {
        case blueMan
        case purpleWizard
        case greyDinosaur
    }

    class func avatar(withType type: AvatarType) -> SKSpriteNode {
        let spriteName: String
        switch type {
        case .blueMan:
            spriteName = "blueManSprite"
        // case .purpleWizard
        //   ...
        default:
            spriteName = "someSprite"
        }

        return SKSpriteNode(imageNamed: spriteName)
    }
}
class ChooseAvatarScene : SKScene {
    let avatarBlueMan = SKSpriteNode.avatar(withType: .blueMan)
    // let avatarWizard = ...
    // let avatarDinosaur = ...

    func setup() {
        avatarBlueMan.position = CGPoint(x: 50, y: 50)
        // avatarWizard.position = ...
        // avatarDinosaur.position = ...

        addChild(avatarBlueMan)
        addChild(avatarWizard)
        addChild(avatarDinosaur)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        // check if any of the touches hit an avatar sprite
    }
}
Related Posts Related Posts :
  • TKChartDataPoint does not conform to expected type Sequence
  • IOS/Swift - Instance member 'app' cannot be used on type ERROR
  • Create show Case view In Tabbar xcode
  • Create IOS App with Cordova on Windows10
  • Get parent process information at runtime on iOS application
  • Destination attribute mapping not showing newly added attribute in xcmodelmappingmodel while Coredata migration
  • How to convert string to NSArray in iOS
  • Converting all Realm Objects to Dictionary at once
  • How to use DACircularProgressView in swift3?
  • Stop Core Data calculation?
  • issue and crash after deletion of last row
  • Multiple UNUserNotifications not firing
  • Drawing a rectangle under text on image Then save
  • auto adjust custom UITableViewCell and Label in it to the text
  • Only use pictures taken through the camera, iOS/Swift
  • UITableView objective-c not populating correctly
  • UNNotification: Custom Sound for LocalNotification is not playing in iOS10
  • Alamofire: How to download zip files sequentially within UITableView
  • iOS Google Tag Manager Integration: How to add multiple containers per App environment?
  • I am getting Exe_Bad_Access(code=1 address=0X38) when I am integrating the CCAvenue Payment Gate way in IOS
  • iOS How to set background image for text in UILabel/UITextView?
  • Notification localization is not working in iOS 10
  • how to show multiple lines in MKAnnotation with autolayout?
  • iOS Provisioning Profile Renewal Process with MDM
  • UITextView check whether text field is empty or not in Objective-C
  • How to open Add Contact form through app
  • Is there a way to recognize, that the app was installed thru firebase dynamic link in didFinishLaunchingWithOptions?
  • iOS - Support ipv4 only API
  • Get IndexPath Value in UICollectionViewCell Class
  • 2d NSArray with enumerated types in objective-c
  • Return the bool statement directly VS using if to return bool
  • Touch ID: Biometry is locked out. Code=-8
  • Values are not updating in my text label from api calling
  • how to manage Height of UITableHeaderView in based on webview content using auto layout
  • viewDidLoad vs ViewWillAppear in IOS
  • Presenting a detail view controller from a map annotation in swift 3?
  • What is industry standard for when to push/pull between core data and remote database
  • Error when moving objects between NSMutableArray
  • Assigning values to class instance from json output
  • Does Facebook SDK support Swift 2.3/3.0?
  • google maps iOS SDK: custom icons to be used as markers
  • Difficulty reading UserDefaults with Fastlane Snapshot
  • Find individual load time of Dynamic Libraries to identify which library consumes more time to load in IOS
  • Can I add local and remote notifications in my iMessage extension?
  • UIImage goes where i tap (But i need it so you can ONLY drag it)
  • How to handle launch options in Swift 3 when a notification is tapped? Getting syntax problems
  • Mismatched colors on UINavigationBar and UISearchBar
  • iOS app that collects data from "Accu-Chek Aviva Connect" BG meter. (Bluetooth Low Energy)
  • React Native (iOS) app loads nicely on wifi; crashes on LTE/cell
  • How to use GADRewardBasedVideoAd
  • Get game request ID / Access Facebook game request notification content
  • Error opening shared document via CloudKit
  • SKPhysicsJointLimit has a elastic behaviour, but i need a strong rope simulation
  • Handing a response in a controller after segueing to another controller
  • Alamofire request gets stuck when entering background?
  • iOS swift: App Transport Security has blocked a cleartext HTTP (http://) resource
  • Full Screen layout for in Xcode 8
  • Provisioning Profile issue after switching to new iPhone in XCode 8
  • how can I center my map on the annotation view only when it is close to the edge of the screen?
  • How can I choose phone number in INSendPaymentIntent
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com