kalbster
24 Jan 2011, 12:16 PM
I have a simple collision detection script I am taking from ExtJS and trying to work with Sencha Touch. The problem I am having is that the getBottom() function returns 0 for my dragged element. The getHeight and getTop functions return properly. I can use the offset and the height to calculate the bottom, but I am curious as to why the getBottom function would return 0 in this case:
<div id="ARENA" style="border:#000000 solid thin; left:0px; background-color:#FFFFFF; width:320px; height:480px; z-index:6000; position:absolute" align="center">
<div id="PAWN" style="left:150px; top:100px; width:97px; height:120px; border:#FF0000 solid thin; z-index:6002; position:absolute; overflow:hidden;" align="center"> </div>
<div id="HIGHLIGHT" style="left:150px; top:250px; width:25px; height:25px; border:#FFF000 solid thin; z-index:6003; position:absolute; overflow:hidden; background:#06F" align="center"> </div>
</div>
<script language="JavaScript">
Ext.setup({
glossOnIcon: false,
onReady: function(){
var target = Ext.get('PAWN');
var highlight = Ext.get('HIGHLIGHT');
new Ext.util.Draggable('HIGHLIGHT', {
revert: false,
constrain:'parent',
listeners: {'offsetchange':function(d,off){
console.log('highlight.getTop(): ' + highlight.getTop() + 'target.getTop(): ' + target.getTop() + ' off.y: ' + off.y + ' (highlight.getTop() + off.y) ' + (highlight.getTop() + off.y) + ' target.getBottom(): ' + target.getBottom() + ' target.getHeight(): ' + target.getHeight());
if (
((highlight.getTop() + off.y) >= target.getTop()) && ((highlight.getTop() + off.y) <= target.getBottom())
){
console.log('HIT HT:' + highlight.getTop() + ' TT: ' + target.getTop() + ' TB: ' + target.getBottom() );
target.setStyle('background','#e4e4e4');
} else {
target.setStyle('background','#000000');
}
}
}
});
}
});
</script>
<div id="ARENA" style="border:#000000 solid thin; left:0px; background-color:#FFFFFF; width:320px; height:480px; z-index:6000; position:absolute" align="center">
<div id="PAWN" style="left:150px; top:100px; width:97px; height:120px; border:#FF0000 solid thin; z-index:6002; position:absolute; overflow:hidden;" align="center"> </div>
<div id="HIGHLIGHT" style="left:150px; top:250px; width:25px; height:25px; border:#FFF000 solid thin; z-index:6003; position:absolute; overflow:hidden; background:#06F" align="center"> </div>
</div>
<script language="JavaScript">
Ext.setup({
glossOnIcon: false,
onReady: function(){
var target = Ext.get('PAWN');
var highlight = Ext.get('HIGHLIGHT');
new Ext.util.Draggable('HIGHLIGHT', {
revert: false,
constrain:'parent',
listeners: {'offsetchange':function(d,off){
console.log('highlight.getTop(): ' + highlight.getTop() + 'target.getTop(): ' + target.getTop() + ' off.y: ' + off.y + ' (highlight.getTop() + off.y) ' + (highlight.getTop() + off.y) + ' target.getBottom(): ' + target.getBottom() + ' target.getHeight(): ' + target.getHeight());
if (
((highlight.getTop() + off.y) >= target.getTop()) && ((highlight.getTop() + off.y) <= target.getBottom())
){
console.log('HIT HT:' + highlight.getTop() + ' TT: ' + target.getTop() + ' TB: ' + target.getBottom() );
target.setStyle('background','#e4e4e4');
} else {
target.setStyle('background','#000000');
}
}
}
});
}
});
</script>