For an assignment i need to have an image i can drag around the screen and when it is over my button(hovering over it) i need the button to change backgrounds. I've made it so the image can be dragged around the screen and i have it so when clicked the button changes backgrounds, but how can i make it so when the image hovers over the button the background changes?
any help would be greatly appreciated
var dragWindow = Ti.UI.createWindow({ title: 'drag and drop', backgroundImage: '/images/board.png' }) // MODEL var lastTouchPosition; // VIEWS var revolver = Titanium.UI.createView({ backgroundImage: "/images/revolver.png", top: 190, left: 110, width: 100, height: 100 }); var rotationTransform = Titanium.UI.create2DMatrix(); // CONTROLLERS revolver.addEventListener('touchstart', function(e){ var touchPos = {x: e.x, y: e.y}; lastTouchPosition = revolver.convertPointToView(touchPos, dragWindow); }); revolver.addEventListener('touchmove', function(e){ var touchPos = {x: e.x, y: e.y}; var newTouchPosition = revolver.convertPointToView(touchPos, dragWindow); // Move revolver by difference between two touch positions revolver.top += newTouchPosition.y - lastTouchPosition.y; revolver.left += newTouchPosition.x - lastTouchPosition.x; lastTouchPosition = newTouchPosition; }); var hoverBtn = Ti.UI.createButton({ title: 'drop', height: platformHeight * 0.2, width: platformWidth * 0.2, center: { x: platformWidth * 0.5, y: platformHeight * 0.48, } }); hoverBtn.addEventListener('hover', function(e){ hoverBtn.backgroundSelectedImage = '/images/blood.png'; }); dragWindow.add(hoverBtn); dragWindow.add(revolver);
1 Answer
I just realised the hoverBtn event listener should be 'click' instead of 'hover', sorry about that
Your Answer
Think you can help? Login to answer this question!