18

Dragging sprites in Scratch

 2 years ago
source link: https://www.codesd.com/item/dragging-sprites-in-scratch.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dragging sprites in Scratch

advertisements

How do I drag sprites during execution in Scratch?


This is covered on the Scratch Wiki.

boisvert's answer is technically correct, however, his script will always drag the sprite from it's center. Using a slightly more advanced script will drag from the spot it was picked up, more like the padlock:

when green flag clicked
forever
  if <<mouse down?> and <touching [mouse-pointer v]?>>
    repeat until <not <mouse down?>>
      set [offset x v] to ((x position) - (mouse x))
      set [offset y v] to ((y position) - (mouse y))
      go to x: ((mouse x) + (offset x)) y: ((mouse y) + (offset y))
    end
  else
    wait until <not <mouse down?>>
  end

(The wiki link above has this is visual blocks format.)

Related Articles

Dragging sprite sheets

I have a simple AS class: package Bubbles { import flash.display.Sprite; import flash.events.MouseEvent; import flash.display.LineScaleMode; import flash.display.CapsStyle; import flash.display.JointStyle; public class Test extends Sprite { public fu

Drag sprite into cocos2d for the iPhone - with maximum velocity

I'm trying to make a game where the user is supposed to drag a sprite up and down on the screen, avoiding incoming obstacles. The last answer here helped me to drag the sprite around on the screen, but I want to set a maximum speed the sprite can be

How to drag sprite on WP7 with XNA?

I can't find any information, how should I create draggable (by touch events) sprite on WP7, can you show me how is it possible to do?You'll have to manually redraw it based on touch changes. The logic should be something like: -- When touch is detec

ActionScript 3 start drag / sprite strangeness

I have a match game, drag and drop a word to a definition. The flow of this game is that after you have answered you click a button and then the game removes the right answers and redisplays the wrong ones. So far that works, what doesn't is that aft

How to use UISwipeGestureRecognizer instead of keysMoved with Swift and SpriteKit?

While trying to drag and drop SKSpriteNodes with the touchesMoved function, the code that lets me drag sprites does not work when I try to swipe them. This is what I have: override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?){

How do I drag and drop a sprite into Swift 3.0?

All i'm trying to do is be able to drag and drop a sprite across the screen. I've tried the following code: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { } override func touchesMoved(touches: Set<UITouch>, with

How to drag and drop multiple sprites in the Inspector

I have a script which handles many sprite arrays. I didn't want to drag them one by one so I wrote a CustomEditor for it that can allow me to assign multiple sprites at once using drag and drop operation: [CustomEditor(typeof(MyMonoBehaviour))] publi

Using gestures with SpriteKit to drag, rotate, and split multiple sprites separately at the same time

I have created an iOS app in which I need to be able to move, rotate and scale a sprite ( I am using Apple's Sprite Kit) at the same time. For the most part I have this working. I currently can touch with 1 finger and move the sprite, and if I use tw

Cocos2d-iPhone Drag anywhere to move the sprite

Ok what I would like to do is duplicate the controls of Space Invaders Evolution. Begin a touch anywhere then drag around and the sprite moves 1:1 with your finger. Sprite can not be moved of screen. I have been using UIGestureRecognizer to handle dr

Drag to rotate the Sprite node in SpriteKit

my problem is I don't know how to rotate a sprite by swipe. I want to rotate it clockwise when I swipe to the left, and other way when I swipe to the right. And how fast I swipe is how fast it rotate, then it slow down and stop. I tried to look for t

How to implement a drag and drop div from scratch with JavaScript?

It should be a combination of CSS and JavaScript. The steps to do should be: Make it on top of all other elements (which property to specity?) Catch the event it is clicked (which event to listen to?) Move the div as mouse moves. But what are the det

Sprite Kit - Drag the physical body on the other

I am developing a game with swift Sprite kit. But I've got a problem, as you can see in the picture I have a number of physical blocks with the same size aligned. When I slide this block above the others sometimes he gets stuck or do small jumps. It

Does SpriteKit support a dense tessellation of a sprite / texture / shape so that it can be freely deformed?

For example if you have an image of a trampoline, and a character jumping on it. Then you want to animate how the trampoline bends down in the center. To do this I would have to take a bitmap and apply it to a densely tessellated OpenGL ES mesh. Then

How to select a circle, drag and drop it in another location in a Windows form?

I am working on a windows form application. When I click anywhere on the form a small circle is drawn using the Graphics.DrawEllipse method. I currently store the center point of the circle in a list to check if the point I clicked lies within the ci

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK